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
#include <iostream>
#include <cstring>
#include <string>
//maybe i need to use void ?
usingnamespace 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.