I am currently in a C++ beginners class and i have an assignment that i need to make. where i create a program and read in from a .txt file a bunch of word such as pig, car, cat. And with these words i need to use arrays and c strings to make a program that will read in the words and take the words, reverse the letters aswell as show the words in opposite order. ex: PIG CAT DOG HOUSE will print out as: ESUOH GOD TAC GIP i hope you understand the type of program i need to create, and also if you wish to help me design the code please use simple techniques which a beginner would understand. thanks gjubi.
char *ReverseWord(char WordToReverse[]) { int i, j; //j = size of WordToReverse char temp; //temp holder for WordToReverse for (i = 0, j = strlen(WordToReverse) - 1; i <= j; i++, j--)//for statement { temp = WordToReverse[i]; WordToReverse[i] = WordToReverse[j]; //move WordToReverse[j] into WordToReverse[i] WordToReverse[j] = temp; //move temp into WordToReverse[j] } return WordToReverse; //return the word in reverse order } //USAGE: char *szReversed - ReverseWord("HOUSE"); //returns ESUOH Code (markup): This what you mean?
WOW yes i think this really helped it seems to look alot like what i have been learning in class, i just was unable to grasp the concept as to how to reverse the arrays. no matter what i thought nothing made sense. but thanks!
When you need to create programs to learn concepts...I'd strongly advise to stay away from solutions. They will only hinder your learning as simple concepts such as arrays, reading in, etc will affect you later on. I'd ask for tips on how to start.
I totally understand what you mean its like im getting someone to do it for me. But i read the C++ book and listen well in class, but i feel that if i can see how the code needs to be written i understand it way better because i never know like what are the exact words i need to write. and it seems that if i see and example that does roughly what i need i can understand it way better and see how everything comes together, i think its just the complicated way that i learn the best.