Thread: Reading Text File (spaces problem)

  1. #1
    Registered User
    Join Date
    Apr 2009

    Reading Text File (spaces problem)

    Hi , I am new in C Programming ,

    I have some code that i write below :

                  int i ;
                  for (i = 0; i < Seat ; i++)
                      fscanf(fp, "%s %d %d",&Seats[i].strName,Seats[i].available,&Seats[i].type);
                  printf("\n\nData successfully loaded...");
    Usually i wanted to do is the program reads each line a text file and put it into a structurer array . But in my text file , i got 1 line of data looks like this

    Jason Liew 0 1

    So i try to printf and see wether the data is it inside the array , but when i type Seat[0].strName , it just show a string "Jason" only , and "Liew" is gone , I was thinking for so long how to wrap the name together . Can anyone guide me and explain what i have go wrong? Thanks

    Regards, kekewong
    Last edited by kekewong; 04-15-2009 at 11:18 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    The %s modifier stops at whitespace. You will need to change the way you use the format specifier, or use a different method of reading your data.

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading a password from a file.
    By medeshago in forum C Programming
    Replies: 15
    Last Post: 12-21-2008, 07:20 AM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  5. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM