Solved

file input problem

Posted on 1998-02-09
6
225 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Would like to move button in a function 3 79
Find Visual Studio Tools 2 113
Safe conversion? 4 72
Are the two lines the same? If not what is the difference? 2 22
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

821 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