Using fscanf to read a file over and over again

This is a discussion on Using fscanf to read a file over and over again within the C Programming forums, part of the General Programming Boards category; I need to analyzed some data over and over again with changed parameters each time, how do I get fscanf ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Location
    London
    Posts
    6

    Using fscanf to read a file over and over again

    I need to analyzed some data over and over again with changed parameters each time, how do I get fscanf to read to the end of a file and then start over at the beginning again?

    Thanks.

  2. #2
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    993
    Code:
    while(you_want_to_loop)
    {
      while(fscanf(fp, format, args) == num_expected_args)
      {
        /* do whatever */
      }
      if(!feof(fp)) /* error converting */
      rewind(fp);
    }
    But maybe it'd be easier to read the data into some data structure and repeatedly analyze that instead.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21