You did not actually describe your problem, you just postulated a cause for it. People (including me) will often skip over posts like that, because if you cannot take the time to express yourself clearly and effectively, why would I?
However, you are obviously very very very new to programming, so bewilderment and naivete are par for the course. Fair enough, but, for your own good and everyone else's, keep in mind what I just mentioned.
LOTS of problems here. First, you should #include <string.h> for strcmp(); because strcmp() returns an int (the default prototype), it will work anyway, but that is not a good habit to get into.
"gets()" is a very depreciated function because it is a security nightmare. Use fgets() instead:
Code:
fgets(string, 20, stdin);
Next, what is the point of this:
Code:
i=0;
while (string[i] !='\0')
{
i++;
}
i=0;
You set i to 0, i then potentially increments to some unknown value. Then you set i to zero. o_O
Next this:
Code:
while (string[i]!='\0')
{
i++;
scanf("%s",&string[i]);
}
j=i;
The program hangs here because of the scanf() call, which reads from standard input (ie, the user console), but you did not prompt the user to input anything. Also, I am pretty sure you do not actually want the user to input anything beyond the first string. What are you trying to do in this loop?
It looks to me like you are trying to copy string backward into reverse, which makes sense -- then you can strcmp() for a palindrome. But the way you are trying to do it does not make any sense.
How about something like:
Code:
int len = strlen(string);
for (i = 0; i < len; i++) {\
reverse[i] = string[len-1-i];
}
reverse[i] = '\0';
There is a small problem with that too, because you will have a newline at the end of the entered string which will mess up the possibility of a palindrome. But hopefully you see the idea...and can ask some specific follow-up questions.