LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-01-2008, 04:44 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: España
Distribution: Suse
Posts: 227

Rep: Reputation: 32
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.
 
Old 10-01-2008, 06:41 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
What language?

In many languages, including BASH, the command is "read".
 
Old 10-01-2008, 07:25 AM   #3
webquinty
Member
 
Registered: Apr 2008
Location: España
Distribution: Suse
Posts: 227

Original Poster
Rep: Reputation: 32
Sorry, in a C programm.

Best regards
 
Old 10-01-2008, 11:24 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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
 
Old 10-01-2008, 11:40 AM   #5
linuxman8786
Member
 
Registered: Sep 2008
Posts: 43

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

Last edited by Tinkster; 10-30-2010 at 03:50 PM.
 
Old 10-01-2008, 12:12 PM   #6
POW R TOC H
Member
 
Registered: Mar 2008
Location: Serbia
Distribution: Fedora
Posts: 37

Rep: Reputation: 15
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.
 
Old 10-01-2008, 03:10 PM   #7
webquinty
Member
 
Registered: Apr 2008
Location: España
Distribution: Suse
Posts: 227

Original Poster
Rep: Reputation: 32
Finally, I do it with fgets.

Thanks a lot.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
doubt in make file shariefbe Linux - Newbie 2 09-24-2008 03:51 AM
Read Only File System? Can't read superblock! haughjd Linux - Software 4 01-15-2008 08:27 AM
Doubt regarding PROC File novicehacker Linux - Kernel 6 12-13-2006 03:51 PM
file execution doubt pongsu Linux - General 2 09-25-2003 01:23 PM
Change from Read only to Read Write File System? justiceisblind Linux - Newbie 3 03-03-2002 07:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration