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

x
?
Solved

c++ code help

Posted on 1998-08-13
2
Medium Priority
?
168 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
[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
2 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
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 video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

705 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