I couldn’t understand some of your code it seemed you were doing some unnecessary things. What was msg
for? This should work if I understood your problem correctly:
#include <stdio.h>
#include <string.h>
void palindrome_check(int ch_length, char text []);
int main(void)
{
char text [100];
/*
int length;
printf("Enter how many characters are in the message: ");
scanf("%d", &length);
Not necessary if you use strlen()*/
printf("Enter the message: ");
fgets(text,100,stdin); /*Using fgets() to allow spaces input*/
/*Strip the newline*/
text [strlen(text)-1]='\0';
palindrome_check(strlen(text),text);
return 0;
}
void palindrome_check(int ch_length, char text [])
{
int i;
for (i = 0; i < ch_length; i++)
{
if(text [i] != text [ch_length-i-1])
{
printf("It's not a palindrome.\n");
return;
}
}
printf("It is a palindrome!\n");
}
solved Error: Segmentation Fault 11 in Palindrome