Question
Write a C Program by the given template (please use that template) Subject Passing char array as argument, accessing argument array. Pointer notion in place
Write a C Program by the given template (please use that template)
Subject
Passing char array as argument, accessing argument array. Pointer notion in place of array index notation.
Specification
Write an C program that reads inputs line by line, and determines whether each line of input forms a case insensitive palindrome. The program terminates when quit is read in.
Implementation
Use the template to start with.
Assume that each line of input contains at most 30 characters but it may contain blanks.
Use fgets to read line by line
- note that the line that is read in using fgets will contain a new line character ' ', right before '\0'. Then you either need to exclude it when processing the array, or, remove the trailing new line character before processing the array. One common approach for the latter is replacing the ' ' with '\0' (implemented for you).
Define a function void printReverse (char *) which prints the argument array reversely (implemented for you).
Define a function int isPalindrome (char *) which determines whether the argument array (string) is a case-insensitive palindrome. Dad is a case-insensitive palindrome, like dad. Do not use array indexing [] throughout your implementation. Instead, use pointers and pointer arithmetic to manipulate the array.
Do not create extra arrays. Manipulate the original array only. Do not use global variables.
Sample Inputs/Outputs:
hello
olleh
Not a case-insensitive palindrome
lisaxxaSIL
LISaxxasil
Is a case-insensitive palindrome.
quit
Template code to follow:
#include
#include
#define SIZE 40
int isPalindrome (char *);
void printReverse (char *);
int main ()
{
int result; char c; int i; int count=0;
char arr[SIZE];
fgets(arr,SIZE,stdin);
while ( )
{
arr[strlen(arr)-1] = '\0'; // remove the trailing
// print backward
printReverse(arr);
result = isPalindrome (arr);
if (result==1)
printf (" Is a case-insensitive palindrome. ");
else
printf (" Not a case-insensitive palindrome. ");
fgets(arr,SIZE,stdin);
}
return 0;
}
int isPalindrome (char * str)
{
}
// assume the was removed manually
void printReverse(char * str){
int i = strlen(str) -1;
while ( i >=0 ){
printf("%c", *(str+i) ); // or putchar(*(str+i));
i--;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started