Solved

file input problem

Posted on 1998-02-09
6
216 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
ID: 1181564
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
ID: 1181565
Thanks for the very quick response, but what exactly is 0x0. I presume NULL.

Am I right?
0
 

Author Comment

by:col
ID: 1181566
Ooops I meant to accept your answer!!! NOT reject it!


SORRY!

Please resubmit your answer, you have the points!


0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 3

Accepted Solution

by:
os012897 earned 100 total points
ID: 1181567
Hi,

No problem ;)

os

0
 

Author Comment

by:col
ID: 1181568
Thanks again!


0
 
LVL 3

Expert Comment

by:os012897
ID: 1181569
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

786 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