Advertisement
ppupil2

Nghien191120

Nov 18th, 2020 (edited)
1,050
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int splitword(char a[], char result[][101]) {
  6.     char b[101], *token;
  7.    
  8.     strcpy(b, a);
  9.     token = strtok(b, " ");
  10.     int i = 0;
  11.     while (token != '\0') {
  12.         strcpy(result[i], token);
  13.         i++;
  14.         token = strtok(NULL," ");
  15.     }
  16.     return i; // size of result[]
  17. }
  18.  
  19. int main(int argc, char *argv[]) {
  20.     char str[101] = "loan an anh toan";
  21.     char find[31];
  22.     char result[50][101];
  23.     int size = splitword(str, result);
  24.    
  25.     printf("Origin string: %s\n", str);
  26.     printf("Enter search name: ");
  27.     gets(find);
  28.    
  29.     printf("Result:\n");
  30.     int i;
  31.     for (i = 0; i < size; i++) {
  32.         if (strstr(result[i], find) != NULL) {
  33.             puts(result[i]);
  34.         }
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement