Thread: Text files scan problem.

  1. #1
    Registered User
    Join Date
    Oct 2011

    Text files scan problem.

    First my text files contain the following information...

    Shanie Programmer Full Time Kuala Lumpur
    Andy Sales Agent Part Time Johor Bahru
    Elaine Database Administrator Full Time Melaka
    Stephanie MIS manager Full Time Penang

    __________________________________________________ ______

    Now my code for scanning this text files...

    #include <stdio.h>
        struct PayRecord {
            char name[50];
            char programme[50];
            char time[50];
            char location[50];
        int main(void)
            FILE *file1;
            struct PayRecord p;
            file1 = fopen("file1.txt", "r");
            if (file1 == NULL) 
                while(fscanf(file1,"%s", & != EOF)
                    fscanf(file1,"%[^\n]", &p.programme);
                    fscanf(file1,"%[^\n]", &p.time);
                    fscanf(file1,"%[^\n]", &p.location);
                    printf("%s ",;
                    printf("%s ", p.programme);
                    printf("%s", p.time);
                    printf("%s", p.location);
            return 0;
    Below is my result...

    Text files scan problem.-untitled-jpg

    As you can see, the problem has shown in the image. So how could I solve this problem? Very thanks you.
    Attached Images Attached Images Text files scan problem.-untitled-jpg 

  2. #2
    Registered User
    Join Date
    Oct 2011
    Opps...sorry. Please ignored the second image. Pls...just view the first image. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read text file, scan and store data into variables?
    By wisdom30 in forum C Programming
    Replies: 8
    Last Post: 04-18-2011, 11:23 PM
  2. Text files problem
    By strickey in forum C++ Programming
    Replies: 4
    Last Post: 11-29-2007, 06:39 AM
  3. problem with text files
    By Gather in forum C++ Programming
    Replies: 27
    Last Post: 06-05-2006, 04:16 PM
  4. Scan some text and replace words
    By Killroy in forum C Programming
    Replies: 3
    Last Post: 11-22-2004, 08:30 AM
  5. text files & notepad problem
    By bigtamscot in forum C Programming
    Replies: 2
    Last Post: 05-01-2003, 04:41 PM