Hi
I'm trying to finish up this program but it won't work and I don't see what I'm doing wrong ...
I have a string input from the user, I'll use string tokenization to split the sentence into words
Code:
#include <string.h>
#include <stdio.h>
#define SIZE 80
int check(char string[], int size);
int main() {
char a[SIZE];
int count=0, l;
char delims[] = " ";
char *token;
printf("Enter a sentence to check for palindromes\n> ");
gets(a);
token = strtok(a,delims);
while(token != NULL) {
l=strlen(token)-1;
puts(token);
token = strtok(NULL, delims);
if(check(token,l) == 1)
count++;
}
printf("Number of palindroms is: %d\n", count);
system("pause");
return 0;
}
int check(char string[], int size) {
int i,flag=0;
char temp[size];
if(size <= 1)
return 0;
for(i=0;i<size;i++)
string[i] = tolower(string[i]);
strcpy(temp,string);
strrev(temp);
if(strcmp(string,temp)==0)
return 1;
}
}
Thank you