C - Getting Single Int from Text File -


i have text file looks this:

4 3 samantha octavia ivan henry 100 90 65 70 99 50 70 88 88 90 98 100 

i wanting read first 2 lines individually , print them out, stands giving me huge number.

inputfile = fopen ("input.txt", "r");  //input     if( inputfile == null)     {         printf ("unable open file input.txt");         exit(exit_failure);     }     else     {         printf ("how many students?\n ");         fscanf (inputfile, "%d", &students);         printf ("%d", &students);         printf ("\nhow many assignments?\n ");         fscanf (inputfile, "%d", &assignments);         printf ("%d", &assignments);         printf ("\n");     } 

what missing here?

simple error!

printing value of &students or &assignments not correct. print value of pointer variable. need following code:

    printf ("how many students?\n ");     fscanf (inputfile, "%d", &students);     printf ("%d", students); // not &students     printf ("\nhow many assignments?\n ");     fscanf (inputfile, "%d", &assignments);     printf ("%d", assignments); // not &assignments     printf ("\n"); 

Comments

Popular posts from this blog

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

wordpress - (T_ENDFOREACH) php error -

Using django-mptt to get only the categories that have items -