Thread: Using fscanf

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

    Join Date
    Apr 2013
    Posts
    23
    Rep Power
    0

    Using fscanf


    I am using fscanf and cant seem to make it pull in 3 words separated by commas, like so:
    firstname,lastname,city

    Here it is

    Code:
    fscanf( pFileIn, "%[^,],%[^,],%c\n", fname , lname, city  ) == 5
    Thanks for your help.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0
    Why would the %c pull in a word? What you've specified there is a single character as the last read field.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    23
    Rep Power
    0
    Yeah i had it set differently and just copy and pasted that in...so do you know how to do it?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    23
    Rep Power
    0
    So what i have now is this
    Code:
     while( fscanf( pFileIn, "%[^,]%*c%[^,]%*c%[^\n]%*\n",fname , lname, city  ) == 5 )
    Does anyone know how to make this work?
  8. #5
  9. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,396
    Rep Power
    1871
    You could try sequences of "%[^,],"
    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
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    23
    Rep Power
    0
    Thanks salem i actually used get and an ignore sequence but thanks a lot for your help, i do appreciate your time.

IMN logo majestic logo threadwatch logo seochat tools logo