•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 429,898 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,351 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 390 | Replies: 6
![]() |
•
•
Join Date: Jun 2008
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
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 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..
•
•
Join Date: Apr 2006
Posts: 35
Reputation:
Rep Power: 3
Solved Threads: 2
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
ssharish
C Syntax (Toggle Plain Text)
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
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/c...ng/strtok.html
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/c...ng/strtok.html
Why so serious?
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,250
Reputation:
Rep Power: 38
Solved Threads: 939
•
•
Join Date: Jun 2008
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
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...
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...
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access activation api blogger blogging blogs code code injection combo dani daniweb data debugging development dreamweaver dropdownlist epilepsy gdata google gpl griefers hackers html innovation javascript key linux microsoft module net news openbsd product programming reuse rss serial source tags vista web wysiwyg xml
- How to print to file (Perl)
- Help on C++ Final Exam !!! (C++)
- separating line by line from textbox with textmode=multiline (ASP.NET)
- ASP Code Works on Local 127.0.0.1 but Not on ISP's Server (ASP)
- CSV file (C)
- Scanning an inputted array of words, and separating each word into a new array? (C)
- Trouble with printing to a file (C)
- get posted form data in python (Python)
Other Threads in the C Forum
- Previous Thread: Reversing doubly linked list?
- Next Thread: Sentence separation..


Linear Mode