//rotate strings
#include
#include
using namespace std;
int main()
{ int j,i;
char s[10],temp;
cout<<“enter string”;
cin>>s;
j=strlen(s);
for(i=0;i<strlen(s)/2;i++)
{
temp = s[i];
s[i]=s[j];
s[j]=temp;
}
cout<<s;
}
//rotate strings
#include
#include
using namespace std;
int main()
{ int j,i;
char s[10],temp;
cout<<“enter string”;
cin>>s;
j=strlen(s);
for(i=0;i<strlen(s)/2;i++)
{
temp = s[i];
s[i]=s[j];
s[j]=temp;
}
cout<<s;
}
the output is not visible
but as its a string , so wont it display the entire word with just writting cout . why to use a loop .
hey @vanshu21, it is not giving any output because j=strlen(s), and at s[j] null character is stored. Inside the for loop that null character comes to s[0] due to s[i]=s[j];.
Now cout prints until it finds null character, and it finds null character at very first index of char array and giving NULL output.
I updated your code here https://ide.codingblocks.com/s/108239.