LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Read a file, doubt!!! (https://www.linuxquestions.org/questions/linux-newbie-8/read-a-file-doubt-673483/)

webquinty 10-01-2008 04:44 AM

Read a file, doubt!!!
 
Hello,

Can I read a file line by line???

lseek is to random access file, but I am interesting in read file line by line.

Best regards.

pixellany 10-01-2008 06:41 AM

What language?

In many languages, including BASH, the command is "read".

webquinty 10-01-2008 07:25 AM

Sorry, in a C programm.

Best regards

pixellany 10-01-2008 11:24 AM

In your C library, isn't there something like stdio?

If I recall correctly, there's a lib function named "read"--or maybe "readline"

Never mind---this just in from Uncle Google:
http://www.mrx.net/c/readfunctions.html

linuxman8786 10-01-2008 11:40 AM

In C it has function readline, ah you must notice what type file saving, binary or txt

POW R TOC H 10-01-2008 12:12 PM

You can use fgets() :
Code:

char * fgets (char *buffer, int max_size, FILE *file_to_read)
First argument points to a buffer you must provide. Second arg is the max line lenght to be read. Third is the file pointer to your file.

fgets returns a NULL pointer if it fails, otherwise it returns a pointer to the beginning of the buffer.

webquinty 10-01-2008 03:10 PM

Finally, I do it with fgets.

Thanks a lot.


All times are GMT -5. The time now is 04:24 PM.