So I wrote a code that inputs a word, takes it's first letter and puts it at the end of the word( eg. "egg" will be "gge", and if we do the same process again it will be "geg" and then finally back to "egg") I want to do this process only 1 time. And I want to use a pointer to memorize the initial value of the word, that is egg, and then the string has to memorize "gge".
This is the code:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char s[100],aux,*P;
int p=1,i,n,k,j;
cin.get(s,100);
i=0;
while(i>=0)
{
P=s; //this is the pointer that SHOULD memorize "egg"
aux=s[0];
for(j=1; j<=n; j++) s[j-1]=s[j];
s[n]=aux;//until here it does the letter thing
break;
}
cout<<P<<endl<<s;//now here the pointer P should be "egg" and the string s should be "gge"
//but the program prints out "gge" and "gge".
return 0;
}
What am I doing wrong and how am I supposed to do what I want?