![]() |
|
#1
|
|||
|
|||
Reading from file to structure until '\n'I'm writing a program that should read information from file and put everything in the structure. The file is written like that: first line is a name of sport and other lines below consist of names and surnames(max 20), then a blank line and a sports name again and so on...
Football Nikopolidis Antonis Sanchez Oswaldo Basketball Sabonis Arvydas Beard Tanoka ... something like that So I'm trying to make that it reads name and surname until it encounters '\n' and if this '\n' is followed by another '\n' (blank line) then it should start reading to another structure and so on... But it doesn't seem to work... The problem is these two lines: for (i=0; (*f!='\n')&&(*(f-1)!='\n'); ) and for (i=1; (*f!='\n')&&(*(f-1)!='\n');i++) How do I change that? CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: Reading from file to structure until '\n'You can't dereference a file pointer. It's supposed to be opaque data type, meaning the underlying fopen system knows what it means, but you don't and shouldn't assume because it could change. It definitely won't give you the current line. What I would do for this is input each line of the file in a loop, and keep a counter of newlines-in-a-row. If that got over 1, go to the next structure.
|
Recent GIDBlog
Not selected for officer school by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| Download files in c for windows operating system | oozsakarya | C Programming Language | 5 | 20-Jun-2006 03:33 |
| Reading and Writing to a text file | raptorhawk | C++ Forum | 16 | 14-Apr-2005 13:09 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The