LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 05:44 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: España
Distribution: Suse
Posts: 218

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, 07:41 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
What language?

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

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

Best regards
 
Old 10-01-2008, 12:24 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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, 12:40 PM   #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 04:50 PM.
 
Old 10-01-2008, 01: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, 04:10 PM   #7
webquinty
Member
 
Registered: Apr 2008
Location: España
Distribution: Suse
Posts: 218

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

Thanks a lot.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 04:51 AM
Read Only File System? Can't read superblock! haughjd Linux - Software 4 01-15-2008 09:27 AM
Doubt regarding PROC File novicehacker Linux - Kernel 6 12-13-2006 04:51 PM
file execution doubt pongsu Linux - General 2 09-25-2003 02:23 PM
Change from Read only to Read Write File System? justiceisblind Linux - Newbie 3 03-03-2002 08:23 PM


All times are GMT -5. The time now is 09:07 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration