View Single Post
Old 04-15-2004, 05:24 PM   #10 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
if i understand the point of this project, it is to learn to use for() or while() loops correctly. if that is the goal, then using strcat() is not what your professor wants.

assuming that, your program is getting there. up until the second "for", it's all good. the first for loop is fine. it copies string1 to string3.

the second loop needs to do the same thing as the first loop, except for one difference. instead of copying string2 to the the beginning of string3, it needs to copy string2 starting at the byte where it stopped copying string1. that is, if your first loop copied 11 characters, your second loop needs to start copying the first character of string2 into the 12th character of string3. this makes the loop more complicated, because there is another index to keep track of.

i've added some printout code to your first loop, just to show what's going on.
Code:
for(index = 0; string1[index] != 0; ++index)
{
	string3[index] = string1[index];
	cout << "copying string1[" << index << "] to string3[" << index << "] (letter '" <<  string1[index] << "')" << endl;
}
//value of string1 is now stored in string 3
cout << index << " letters copied" << endl;
joe_bruin is offline   Reply With Quote