Solved

c++ code help

Posted on 1998-08-13
2
160 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 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…

920 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

17 Experts available now in Live!

Get 1:1 Help Now