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