hello..
I m designing a STATISTICAL SUMMARIZER in C..
This software will create the summary of a text file submitted by
the user..
The first step is to separate line in the text file..
I hav almost completed this step..
but there are some limitations..
Suppose if text file hav this input..e.g

Hello! This is MAYANK. I am a Student of "nitk."
Working on a project.


then how i will separate these lines??
can u provide me with a code of line separation..

I would make an array of strings, one element for each line. Than use something like getchar() to read in one character at a time until you find a '\n' (newline) character. Then start using the next element and read in the next line likewise until you reach the end of the file.

Have a look at a function calle3d fgets which is defined under stdio.h library. This function will do what excatly you want. It read a line of text from the text file until it EOF which then return NULL. The sample usage of that function can be found bellow

FILE *fp;
char buffer[BUFSIZ];

if( ( fp = fopen( <filename>, "r") ) != NULL )
{
    while( fgets( buffer, BUFSIZ, fp) != NULL )
           printf( "%s", buffer );
           /* You could backup this buffer
              by copying it on to a different
              char array */
}

ssharish

commented: simple +4

the function that would be helpful for you here, i think, is STRTOK

in the string.h library.

it will separate any text into "tokens" based on a set of "delimiters"

your "tokens" will be individual lines, and your set of "delimiters" will simply be the newline character '\n'

once you have your individual lines you can insert anything you want in between them, and then rewrite them to a buffer or another text file as you desire.

http://www.cplusplus.com/reference/clibrary/cstring/strtok.html

the function that would be helpful for you here, i think, is STRTOK

Nope -- just use fgets() as previously suggested. No need to read the file one character at a time just to find line terminators because that's doing it the hard way.

oh, dur.

you're right.

brainfart.

thnks all of u...
bt i m nt looking for separating the sentences..
for eg.
input
Hello! This is MAYANK. I am a Student of "nitk."
Working on a project.

output:
Hello! This is MAYANK.
I am a Student of "nitk."
Working on a project.

sorry for giving the heading as line separation
it would be rather sentence separation..
i hav started new thread with this name..
do reply to that thrad..
thnku...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.