Thread: Extracting data out from txt file seperated by ";"

  1. #1
    Registered User
    Join Date
    Nov 2009

    Extracting data out from txt file seperated by ";"

    Hi ,

    i am having this problem of extracting data out from txt file being seperated by ;.


    How is your day?;Fine
    Where are you now?;At your house

    My code is as follow:

    char *ques[20];
    char *ans[20];
    int i=0;
    FILE *fp;
    fp=fopen("qna.txt", "r");
    if ( fp == 0 )
    printf( "Could not open file\n" );
    while(fgets(fileInput, sizeof fileInput, fp))   
    if(sscanf(fileInput, "%s,%s", &ques[i], &ans[i]) == 2)
    fclose( fp );

    The difficulties i faced was that i am not able to successfully extract the data out from the text file and stored it into both que[] and ans[].

    Errors keep coming out from the "%s,%s". And i guess i might have key in the wrong placeholders..

    Anyone can help ? Thanks in advance...

  2. #2
    Make Fortran great again Epy's Avatar
    Join Date
    Sep 2009
    California, USA
    Well, you might try "%s;%s" instead of "%s,%s"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP with storing serial port data into txt file
    By inmaterichard in forum C Programming
    Replies: 2
    Last Post: 04-02-2008, 02:20 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Please Help Reading Data From A File
    By NickHolmes in forum C Programming
    Replies: 5
    Last Post: 05-29-2005, 11:24 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM