- Define two 80-character strings called str and rev(assuming your string will not exceed 79 characters). Your string can be of any length, but remember that the last position in the string is fixed for the null character \0:
char str[80],rev[80];
- Enter characters that will be assigned to the str string:
printf("Enter a string: ");scanf("%s",str);
- Compute the length of the string using the strlen function and assign this to the n variable:
n=strlen(str);
- Execute a for loop in reverse order to access the characters in the str string in reverse order, and then assign them to the rev string:
for(i=n-1;i >=0; i--){ rev[x]=str[i]; x++;}rev[x]='\0';
- Compare the two strings, str and rev, using strcmp:
if(strcmp(str,rev)==0) ...