Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to read one line of the text file, save it to a buffer, send the buffer over a udp socket and then go and read the second line and so on..

So far, since I knew the data type of the text to be read from the text file, I had been using fscanf() to read each line from the text file. But now I don't know the data types so it is not possible for me to use this function anymore. Is there any other way to read text file line by line.

Note: The length of each line may vary.
Posted
Comments
Sergey Alexandrovich Kryukov 10-May-13 1:10am    
Fully illogical question. If you get "any other way" to read the lines of the files, they still will be the same lines. It won't solve the problem of the file "format".
—SA
ayesha hassan 10-May-13 1:35am    
I guess file format i.e. ".txt" is defined :(
The data types of the contents inside the file is not known. i.e file may have char as well as int.
Sergey Alexandrovich Kryukov 10-May-13 9:26am    
OK, you have no problem at all, except the lack of some basic skill and understanding.
—SA
ayesha hassan 10-May-13 1:39am    
Read one line from a text file using fgets() and stored it in char[] but what I get is corrupted data :(
Richard MacCutchan 10-May-13 3:48am    
If you just want the 'pure' content of the file transferred across the socket then use fread() and transfer some fixed number of bytes at each message. The receiver can then re-create the file by using fwrite().

1 solution

If you get "any other way" to read the lines of the files, they still will be the same lines. It won't solve the problem of the file "format". The question makes no sense.

For example, you can use std::istream::getline:
http://www.cplusplus.com/reference/istream/istream/getline/[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900