0
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fptr;
int val;
char filename[100], c;
printf("Enter the filename to open \n");
scanf("%s", filename);
fptr = fopen(filename, "r");
if (fptr == NULL){
    printf("error\n");
    exit(0);
}

while((fscanf(fptr,"%c %d",&c,&val))==2)
{
    printf("%c %d\n",c,val);
}
fclose(fptr);
return 0;
}

I am trying to scan values from a text file using fscanf but i am able to read only one value even though i kept a loop.
sample input:

d 7
i 10
i 5
i 10
d 10

my output is:

d 7
BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70

0 Answers0