How can i swap word

How can i swap word in C++ i don't know how to do it ?
Input two character arrays Name1 and Name2 of the size 12. Print both arrays in reverse order as shown in the sample input an output. If both arrays are identical then print “Arrays are same!” otherwise print “Arrays are different!” Hint: Use the function strlen(…) to find the length of a C-String, use the function strcmp(…) to compare two C-Strings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream> 
#include <cstring> 
#include <string> 
//maybe i need to use void ?
using namespace std; 
int main() 
{ 
char Name1[12] ; 
char Name2[12]; 
char name1,name2; 
cout<<"please enter Name #1 : "; 
cin>>Name1; 
cout<<endl; 
cout<<"please enter Name #2 : "; 
cin>>Name2; 
cout<<endl; 
//i have to swap 
cout<<name1; 
cout<<name2; 
cout<<endl<<endl; 
if (name1==name2) 
cout<<"Arrays are same!"; 
if(name2!=name1) 
cout<<"Arrays are different!"; 
}
If you want to do it this way then I would suggest looking into the data structure most closely related to this so you can actually understand the theory behind what you are doing. What you will want to research is a stack data structure which has a first in last out property. I understand this may be a little bit complicated but try doing a little bit of research on stacks and try to implement the abstraction. A common application of stacks is what you are attempting to do, reverse a string.

erock
Topic archived. No new replies allowed.