structure and reading a text file
Please support our C advertiser: Programming Forums
Thread Solved
![]() |
•
•
Posts: 3
Reputation:
Solved Threads: 0
hi,
how can i read a text file "textfile.txt" with a structure? (in C)
thanks
the structure is in this form.
how can i read a text file "textfile.txt" with a structure? (in C)
thanks
the structure is in this form.
c Syntax (Toggle Plain Text)
typedef struct list { char ID[9]; char YR[10]; char lname[14]; char fname[24]; }LIST[256];
Last edited by Ancient Dragon : Jan 7th, 2009 at 9:34 am. Reason: add code tags
you could do something like this:
Of course you will have to put the above in a loop after opening the file for reading.
fscanf(fp,"%s%s%s", List[i].ID, List[i].YR, List[i].lname); // get the first name separately because it may be composed of // two or more names with spaces, so fscanf() will not work with this. fgets(List[i].fname, sizeof(List[i].fname, fp);
Of course you will have to put the above in a loop after opening the file for reading.
Last edited by Ancient Dragon : Jan 7th, 2009 at 11:04 am.
![]() |
Similar Threads
Other Threads in the C Forum
- Reading Data from text file (C++)
- Dynamic array (C++)
- Problem with strtok() for data structure creation (C++)
- dynamically update pages (HTML and CSS)
- read text file (C)
- struct linked list problem (C)
- header file/ classes (C++)
- Reading in a *.csv file and loading the data into an Array (Java)
- How to delete a data structure in Builder 6.0? (C++)
- file input and output (C)
Other Threads in the C Forum
- Previous Thread: Problem with array of pointers
- Next Thread: Wireless networks
•
•
•
•
Views: 682 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)






Linear Mode