Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int splitword(char a[], char result[][101]) {
- char b[101], *token;
- strcpy(b, a);
- token = strtok(b, " ");
- int i = 0;
- while (token != '\0') {
- strcpy(result[i], token);
- i++;
- token = strtok(NULL," ");
- }
- return i; // size of result[]
- }
- int main(int argc, char *argv[]) {
- char str[101] = "loan an anh toan";
- char find[31];
- char result[50][101];
- int size = splitword(str, result);
- printf("Origin string: %s\n", str);
- printf("Enter search name: ");
- gets(find);
- printf("Result:\n");
- int i;
- for (i = 0; i < size; i++) {
- if (strstr(result[i], find) != NULL) {
- puts(result[i]);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement