Ok so i have a text file database.txt.
Each line is a user with the format below
\"John Smith\"| 4| 80.00| \"123 Lollipop Lane\"| \"New Jersey\"| \
The problem is that your fscanf
will never read the newline at the end of the first line. So when it is called the second time, it will fail (returning 0, not EOF) and read nothing, leaving buffer
unchanged.
You could add a call to fscanf("%*[\n]");
at the end of your while loop to skip the newline (and any blank lines that might occur). Or you could just use fgets
instead, which also makes it easier to avoid the potential buffer overflow problem.