Text files scan problem.

This is a discussion on Text files scan problem. within the C Programming forums, part of the General Programming Boards category; First my text files contain the following information... Shanie Programmer Full Time Kuala Lumpur Andy Sales Agent Part Time Johor ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    67

    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...

    Code:
    #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) 
            {
                printf("Error");
            }
    
            else 
            {
                while(fscanf(file1,"%s", &p.name) != EOF)
                {
                    fscanf(file1,"%[^\n]", &p.programme);
                    fscanf(file1,"%[^\n]", &p.time);
                    fscanf(file1,"%[^\n]", &p.location);
                    
                    printf("%s ", p.name);
                    printf("%s ", p.programme);
                    printf("%s", p.time);
                    printf("%s", p.location);
                    printf("\n");
                }
    
            }
    
            return 0;
    
        }
    Below is my result...

    Name:  untitled.JPG
Views: 326
Size:  87.2 KB

    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  

  2. #2
    Registered User
    Join Date
    Oct 2011
    Posts
    67
    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-19-2011, 12:23 AM
  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, 05: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, 05:41 PM

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