I am reading the key and value for every pair in the list, ignoring the whitespaces and trying to print it. My file consists of data like:
(2, 50) (4, 30) (9, 30) (10, 400) (-5, -40)
(7, 20) (19, 200) (20, 50) (-18, -200) (-2, 29)
(2, 67) (4, 35) (9, 45) (-18, 100)
I am trying to get the integers inside the parenetheses one by one. For eg.
m=2
n=50
m=4
n=30
I've tried to read data from the file till the file ends. Scan and print the m and n values.
int m,n;
FILE* file = fopen("File1.txt", "r"); // open a file
while (!feof (file))
{
fscanf (file, "(%d, %d)", &m, &n);
printf("m is %d:", m);
printf("n is %d:", n);
}
//close the file after opening
fclose (file);
The build is successful while running the code whereas
m is 2:n is 50:m is 2:n is 50:m is 2:n is 50:m is 2:n is 50:m is 2:n is 50:m is 2:n is 50:m is 2:
is printing endlessly instead of reading the integers from the file.
Kindly help.