Submitted by admin on Wed, 03/23/2016 - 15:57
We are given a string. We need to split a string into words and find a words with lenght more than 3. Use array of pointers to store words.
#include <stdio.h> #include <conio.h> #include <string.h> #include <alloc.h> #include <ctype.h> #include <limits.h> int main(int argc, char* argv[]) { char *s1, *s[10]; int i=0, j, sim=0, l, k, h, n1, n2, min; s1 = (char*)calloc(100, sizeof(char)); puts("Enter string #1:"); gets(s1); n1 = strlen(s1); k = 0; while (i < n1) { while ( (i < n1) && (!isalpha(s1[i])) ) i++; j = i; while ( (j < n1) && (isalpha(s1[j])) ) j++; s[k] = (char*) calloc( j-i, sizeof(char) ); for (h = i ; h < j; h++) s[k][h-i] = s1[h]; s[k++][j-i] = '\0'; i = j; } for (i = 0; i < k; i++) if (strlen(s[i]) > 3) puts(s[i]); free(s1); for (i = 0; i < k; i++) free(s[i]); getch(); return 0; }