Design a C program that checks whether a string is a palindrome. The string can
ID: 3796774 • Letter: D
Question
Design a C program
that checks whether a string is a palindrome. The string can be several words or just a single word:
Acme Palindrome Finder
Enter a string to check: Was it a rat I saw?
Analyzing input. Please wait………
Your input: Was it a rat I saw
Reverse input: was I tar a ti saW
Congratulations! Palindrome found!
Minimum Requirements:
• Your program should pick a random number from 3 to 7 and wait that many seconds before displaying the results. Use functions from the time.h library to get the current time. Use a loop to query the system time until the desired number of seconds have passed.
• The input should not be case sensitive.
• The program should work with numbers as well as letters.
• White space is not part of a palindrome, as you can see in the above example
First few step should look like the following:
Print the program title and instructions on the screen.
Get user input
Print “Please wait” on the screen.
Delay a random number of seconds from 3 to 7. Print a “.” on the same line as “Please wait” each second that passes.
Make a working copy of the input string.
Remove punctuation and white space from the string copy. Make all letters uppercase.
Analyze the copy for a possible palindrome.
Print the original input string forwards and backwards.
Display whether the string is a palindrome.
The following outcomes needs to be met:
Works with numbers and letters .
Works with mixed case letters and punctuation in the input
Works with a single word or several words
Displays the user input string forwards and backwards, with the first characters lined up in the same column
Explanation / Answer
#include<string.h>
#include<stdio.h>
main()
{
char *str,*rev;
int j,k;
printf(" Enter the string");
scanf("%s", str);
for(j=strlen(str)-1, k=0,j>=0;- -j, ++k)
rev[k]=str[j];
rev[k]=' ' ;
if(strcmp(rev,str) )
{
printf("GIven string is not a palindrome");
}
else
{
printf(" Given string is palindrome");
}
return 0;
}