Submitted by admin on Wed, 03/23/2016 - 15:35
We are given a string. We need to split a string into words and find a symmetrical words.
#include <stdio.h> #include <conio.h> #include <string.h> #include <alloc.h> #include <ctype.h> int main(int argc, char* argv[]) { char* s; int i=0, j, sim=0, l, k, n; s = (char*)calloc(100, sizeof(char)); puts("Enter string:"); gets(s); n = strlen(s); while (i < n) { while ( (i < n) && (!isalpha(s[i])) ) i++; j = i; while ( (j < n) && (isalpha(s[j])) ) j++; l = 0; k = 0; while ( i + k < j - 1 - k ) { if ( s[i+k] != s[j-1-k]) { l = 1; break; } k++; } if ( (i < n) && (l == 0) ) sim++; i = j; } printf("sim = %d",sim); free(s); getch(); return 0; }