Solved

file input problem

Posted on 1998-02-09
6
197 Views
Last Modified: 2011-09-20
I'm STUCK please help!!!

I'm trying to read in a textual file one sentance at a time, NOT one line at a time.
I know you can read a line in by e.g.
infile.getline(line, LINELENGTH, '\n')
I also know that '\n' can be exchanged for '.' which would partly solve the problem, however how could I get rid in the  '\n' characters that are in the middle of the sentance?? When I tried to read in the next sentance???

If possible, If the very first word of each sentance I want to do something else with it as well.

0
Comment
Question by:col
  • 3
  • 3
6 Comments
 
LVL 3

Expert Comment

by:os012897
Comment Utility
Hi col,

I would go for the straightforward solution:

Assuming line is a char *:

nfile.getline(line, LINELENGTH, '.');
for (int index = 0; line[index] != 0x0, ++ index)
    if (line[index] == '\n') line[index] = " ";

I do not understand the last part of your question, but you can get the first word of each sentence with:

firstWord = strtok (line, " \t"); // words separated by                                   // whitespace or tab

Hope that helps,

     os

0
 

Author Comment

by:col
Comment Utility
Thanks for the very quick response, but what exactly is 0x0. I presume NULL.

Am I right?
0
 

Author Comment

by:col
Comment Utility
Ooops I meant to accept your answer!!! NOT reject it!


SORRY!

Please resubmit your answer, you have the points!


0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Accepted Solution

by:
os012897 earned 100 total points
Comment Utility
Hi,

No problem ;)

os

0
 

Author Comment

by:col
Comment Utility
Thanks again!


0
 
LVL 3

Expert Comment

by:os012897
Comment Utility
I forgot:

0x0 is the 0-character that terminates each regular C-style string. You can write just 0 too.

NULL is used for the null-pointer which has also 0 as value, but you should not use it for the 0-character as it has a different meaning.

os

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now