#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Using fgets and fprint


    char s[100];
    FILE *fp;
    fp=fopen("E:\\proyectofinal\\nueve.txt", "r");

    fgets(s,100,fp) ;
    fprintf(stdout, "%s", s);

    fclose(fp);

    I want it to scan and print the whole of my file, but it only prints out the first line of it. What am I doing wrong?
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    Try
    while ( fgets(s,100,fp) != NULL )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0
    Originally Posted by salem
    Try
    while ( fgets(s,100,fp) != NULL )
    thanks!, that worked

IMN logo majestic logo threadwatch logo seochat tools logo