![]() |
|
#1
|
|||
|
|||
How do you read strings from a file...?Hello everyone, I just would like to ask some questions regarding the FILE output/input. I was able to write strings on a file using fprintf, but how can i read all the strings that i had inserted on it? Is it possible to use looping statements? Could you kindly give me some examples please?
And one more questions, how do you pick strings on a file randomly? say, i have inputted 10 words on the file and wanted to pick 5 random words. Is it possible? it would be great if you kindly post some examples... Sorry i am still learning C. Thanks in advance and God bless to you all! |
|
#2
|
|||
|
|||
Re: How do you read strings from a file...?say you called your FILE* fFile, you could try something like this:
CPP / C++ / C Code:
Last edited by LuciWiz : 27-Sep-2006 at 01:38.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#3
|
|||
|
|||
Re: How do you read strings from a file...?Thanks for the reply, it helps me alot. But how do you pick the words from a file randomly?
|
|
#4
|
|||
|
|||
Re: How do you read strings from a file...?read all the strings to the array and then choose 5 of them randomly
|
|
#5
|
|||
|
|||
Re: How do you read strings from a file...?Hi, there. I tried to read all the strings from the file using for loop but it only reads the first line only. I can retrieve all strings from the file by manually read them one by one. How do you read all the strings using loop? Sorry for being a noob.
|
|
#6
|
|||
|
|||
Re: How do you read strings from a file...?the byte's value -1 denotes the end of the file. So when i find this byte in the text i know that it's the end of the file.
|
|
#7
|
|||
|
|||
Re: How do you read strings from a file...?Quote:
In the first response to this thread, niek_e gave an example of a loop that reads multiple lines from the file. Did you try something like that? If you didn't, that may be OK (that's probably one of the better ways, but there are other ways). How can we tell why your method didn't work if we don't know what you tried. In other words: Show Us Some Code. Regards, Dave |
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? 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 |
| Download files in c for windows operating system | oozsakarya | C Programming Language | 5 | 20-Jun-2006 04:33 |
| How to detect end of file with read() function call? | nkhambal | C Programming Language | 6 | 12-Oct-2004 02:08 |
| 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