Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Windows Win32 programming file , +
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 9-May-13 20:00pm
Comments
Sergey Alexandrovich Kryukov at 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 at 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 at 10-May-13 9:26am
   
OK, you have no problem at all, except the lack of some basic skill and understanding.
—SA
ayesha hassan at 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 at 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().
ayesha hassan at 10-May-13 3:57am
   
I think this is going to work. Infact, Wouldn't it be better to read only fixed number of bytes using fread(), transfer them over the socket and then read the next bytes?
By the way, Thank you so much :)

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 10 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100