Solved

file input problem

Posted on 1998-02-09
6
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

738 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