| | |
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 |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






