|
このプログラムは、入力された文字列が空白類文字を含む場合について
考慮していません。
#include <stdio.h>
#include <string.h>
#define STRING_MAX 1024
#define TARGET_MAX 80
int main(void)
{
char string[STRING_MAX], word[TARGET_MAX], *p;
int count = 0;
printf("文字列を入力: "); scanf("%s", string);
printf("キーワードを入力: "); scanf("%s", word);
for (p = string; p = strstr(p, word); p += strlen(word))
count++;
printf("キーワードの個数 = %d\n", count);
return 0;
}
|