![]() |
|
#1
|
|||
|
|||
Reading in from a tab delimited text file?Hi,
I have an assignment to do a minimum spanning tree. I've been given a text file such as the following: York (tab) Leeds (tab) 60 London (tab) manchester (tab) 130 It's basically two cities and the distance between then, the text file therefore consits of three coloumns. I need to start my program by reading all of these values, but I don't know how to read them in since they're seperated by tabs. I'd really appriciate some help Thank you, Selen |
|
#2
|
|||
|
|||
Re: Reading in from a tab delimited text file?Quote:
If your assignment is a spanning tree, I would assume that you have had basic I/O. You might use fgets(), strtok(), sscanf() to get the data for each line. Or you could just do it the old-fashioned way: do a little work, but maintain complete control. The program specification will require that there be a tab character after the first city and a tab character after the second city. The program specification might also state the longest name that would be allowed. (How far is it from London to Llanfairpwllgwyngyllgogerychwyrndrobwllllantysilio gogogoch?) If there is a bad input datum (no tab character, for example), you should probably specify what to do about this case also. Here is one very elementary way to read the first name on the first line of the file: Code:
CPP / C++ / C Code:
I would probably test for EOF, and maybe '\n' inside the loop (and exit with an error message if either is encountered before the required '\t'). Maybe non-printing characters also. It's your call. Regards, Dave |
|
#3
|
|||
|
|||
Re: Reading in from a tab delimited text file?Quote:
Haha that looks familier...just starting mine...hope ive left enough time (unlike the predictive text) mine reads in each line Quote:
then steps thro the line putting each char into an array untill a tab is reached |
|
#4
|
|||
|
|||
Re: Reading in from a tab delimited text file?hahaha caught red-handed on a forum !! i've finished my MST now..just gonna finish the report today hopefully!
not sure who you are in electronics you are though, don't know the names of ppl very well |
Recent GIDBlog
Writing a book 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 08:44 |
| Having trouble reading in floats from a text file into a 2-dim array | CT++ | C++ Forum | 3 | 24-Jun-2006 01:01 |
| Reading and Writing to a text file | raptorhawk | C++ Forum | 16 | 14-Apr-2005 14:09 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 11:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 12:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The