Computer Science Download the template program palindrome.c and the input data file data11.txt. Fill out the function palindrome() to determine if the passed string is a palindrome (a string that reads the same forward and backward). Return 1 from the function if it was passed a palindrome and 0 otherwise. Fill out the function newPalindrome() to allocate an instance of the given Palindrome structure and return it
Computer Science
Download the template
There are __ palindromes in the ____ line input file
anna, ... , aga
Don't forget to free the allocated storage at the end of the program. There is a class to delPalindromes() just for that purpose.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define WORDSZ 30
int palindrome(char *_line) {
/* your code goes here */
return _pal; // return 1 if a palindrome, 0 otherwise
}
typedef struct Palindrome {
char *word;
struct Palindrome *link;
} Palindrome;
Palindrome *newPalindrome(char *pal) {
Palindrome *nwp;
/* your code goes here */
}
void delPalindrome(Palindrome *pal) {
/* your code goes here */
}
void delPalindromes(Palindrome *pal) {
Palindrome *nxt;
/* your code goes here */
}
int main(int argc, char *argv[]) {
int ct;
int pct;
char word[WORDSZ];
Palindrome *palList, *pal;
ct = 0;
pct = 0;
palList = 0;
while (0 <= scanf("%s", word))
{
/* your code goes here */
}
printf("There are %d palindromes in the %d line input file\n", pct, ct);
if (pct > 0)
{
/* your code goes here */
}
delPalindromes(palList);
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps