Question: Hi I have a program I have done that is a palendrome. I have it correct I just need to have int main () in
Hi I have a program I have done that is a palendrome. I have it correct I just need to have int main () in the begginning of my code. Can you rearrange it so there will be no build erros thanks!
#include
#include
#include
#include
#include
void removeSpaces(char *str)
{
int count = 0;
for (int i = 0; str[i]; i++)
if (str[i] != ' ')
str[count++] = str[i];
str[count] = '\0';
}
bool sentencePalindrome(char str[])
{
int l = 0, h = strlen(str) -1;
printf(" The input sentence has %d characters", h);
removeSpaces(str);
int h1 = strlen(str) -1;
printf(" The test sentence has %d characters", h1);
printf(" The max index is %d ", (h1-1));
printf(" The converted sentence is: %s", str);
// Lowercase string
for (int i = 0; i < h; i++)
str[i] = tolower(str[i]);
while (l <= h) {
if (!(str[l] >= 'a' && str[l] <= 'z'))
{
l++;
}
else if (!(str[h] >= 'a' && str[h] <= 'z'))
{ h--; }
else if (str[l] == str[h])
{ l++, h--; }
else
{ return false; }
}
// Returns true if sentence is palindrome
return true;
}
int main()
{
char str[100];
printf(" This program tests a sentence to see if it is a palindrome.");
printf(" Please enter a sentence and then hit enter ");
fgets (str, 100, stdin);
if (sentencePalindrome(str))
printf(" Sentence is palindrome. ");
else
printf(" Sentence is not palindrome. ");
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
