faqts : Computers : Programming : Languages : C

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 9 people (56%) answered Yes
Recently 5 of 9 people (56%) answered Yes

Entry

Does anybody know how to open a text file and evaluate one line at a time?

Sep 22nd, 2004 02:29
Ankit Sharma, nial mueck, Chris Ollar,


you need to use some thing like fopen or if you are using a unix system
( this may work in mindows ) then you can ues the open(), read(),
wright() and lseek() functions. If you use them you can look at the data
one byte at a time if you like.
======================================================================
Hi 
 Let us take a example.
suppose you want to open a file abc and want to read it's contents line 
by line. So following code will help:
FILE *fp;
char buff[1024];
fp = fopen(filename, "r");   /* check the error if returned*/
while(1)
{
   if(!fgets(buff,1024,fp))
      {
	printf("Error in reading \n");
	break;
      }
   /* Now buffer buff contains the info contained in a line of the file 
*/
/* So do the processing */
}
Ankit Sharma