Solved

c++ code help

Posted on 1998-08-13
2
159 Views
Last Modified: 2010-04-10
how do I read in a string from a file as a charactor array and then reverse the letters of each word ? e.g.

if the file contained :

This is a test
This is a test2

you would read in "This is a test" as a charactor array then reverse the letters to say "sihT si a tset" then read in the second line and reverse those letters as well.
0
Comment
Question by:astroyboyy
2 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 total points
ID: 1170261
1. open the file (fopen in file.h)

2. while not at the end of the file
i) read a line in to a character array (fread in file.h)
ii) use _strrev (most compilers have this, possibly without the leading underscore)in string.h to reverse the string

3. close the file (fclose in file.h)

0
 
LVL 11

Expert Comment

by:alexo
ID: 1170262
A C answer to a C++ question?  Duh...

STL makes the solution trivial.  Create a vector<string>, fill it using istream_iterators, use the for_each() function to invoke the reverse() function on all the strings in the vector.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

747 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