NOT UNDERSTANDING THE LINE OF CODE

16 views
Skip to first unread message

RIDA ZAHRA ALI

unread,
May 12, 2013, 4:44:05 AM5/12/13
to cs1003-s...@googlegroups.com
Assalam-o-alaikum sir/mam!


                                what is this line of code doing?

             # include <stdio.h>

             void main ()

            {

                  FILE *fp;  char str [25], str1 [25];

                  int x, i = 0;

                  fp = fopen ("format.txt", "r");

                  while (!feof (fp))

                  {

                    if (fscanf (fp, "%s%s%d", str, str2, &x) < 0)  // NOT UNDERSTANDING  

                    break; 

                     printf ("%d. %s %s %d\n", ++i, str, str1, x);

                  }

           }


     Is fscanf returning something? please explain this line.

Sami Ullah Kashif

unread,
May 12, 2013, 6:26:55 AM5/12/13
to cs1003-s...@googlegroups.com
If there is nothing to read, then fscanf() returns -1. Since -1 < 0, the condition would become true and break would be executed and code would exit from the while loop.

Regards,
Sami
Reply all
Reply to author
Forward
0 new messages