| | |
structure and reading a text file
Thread Solved |
•
•
Join Date: Jan 2009
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 10:34 am. Reason: add code tags
Don't know the answer to your question until I know the contents of the text file. Without that knowledge, generally I would use fgets() to read a line, then parse it into its individual parts into the structure.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
you could do something like this:
Of course you will have to put the above in a loop after opening the file for reading.
C Syntax (Toggle Plain Text)
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 12:04 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Reading in a *.csv file and loading the data into an Array (Java)
- 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++)
- 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
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






