Jan 30, 2020 at 3:55pm Jan 30, 2020 at 3:55pm UTC
Hint: no need to create a new string or mess with char arrays[].
Hint 2: how many swaps are needed to fully exchange every pair of characters?
Jan 30, 2020 at 4:08pm Jan 30, 2020 at 4:08pm UTC
This may be wrong, might not even compile (probably wont)
But this was my take (done in a phone so go easy on me). But you ain't never gonna learn getting answers off a forum like this
[Code]
#include <iostream>
using namespace std;
void stringRev(char *s);
int main()
{
char str[]="Happy Day";
cout << stringRev(str);
system ("pause > 0");
return 0;
}
char* stringRev(char *s)
{
char* tmp;
tmp = new char;
int i, cnt;
for( i=0;s[i]!=’\0’;i++ ; )
{
cout << s[i] << endl;
cnt++;
}
for( i=0; i<cnt; i++)
{
tmp[i] = s[cnt-i];
}
tmp[i]='\0';
For(i=0;i<cnt;i++){
Cout<<”tmp[i] “<<tmp[i]<<” s[i] “<<s[i]<<endl;
}
return tmp;
}
[/code]
Idk why this looks like this....whatever
I just noticed that there maybe some dereferenceing that needs to happen to set and display the data. I'm not really that thoroughly schooled in pointers yet to really be able to tell.
Last edited on Jan 30, 2020 at 5:19pm Jan 30, 2020 at 5:19pm UTC