Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


file input problem

Posted on 1998-02-09
Medium Priority
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.

Question by:col
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

Expert Comment

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,



Author Comment

ID: 1181565
Thanks for the very quick response, but what exactly is 0x0. I presume NULL.

Am I right?

Author Comment

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


Please resubmit your answer, you have the points!

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!


Accepted Solution

os012897 earned 400 total points
ID: 1181567

No problem ;)



Author Comment

ID: 1181568
Thanks again!


Expert Comment

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.



Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

721 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