strstrについて
Posted: 2007年6月23日(土) 02:10
strstrについての課題です。
strstr関数について調べてはみたのですが、数を数えるのをどうやって作ればよいか見当もつきません。
説明もお願いします。
次のプログラムの英文の文章の中に冠詞の[the]の数をstrstr関数を使って数えるプログラムを作成する。
thenなどは数えないようにする。
#include <stdio.h>
#include <string.h>
int main(void)
{
int i,len;
char *found;
char a[/url]="Chiba University was founded in 1949, unifying several regional former national colleges and schools such as Chiba Medical College and Chiba Normal School. Its fundamental mission since then has been, as encapsulated by the inscription on the University Bell, ad altiora semper (always toward the higher), to equip students with the ability to make mature and informed judgments while nurturing and guiding their creativity. Pursuing these goals of excellence has resulted in Chiba University becoming one of the leading academic research centers of Japan.";
len = strlen(a);
for(i=0;i<len;i++){
found = strstr(a+i, "the");
if ((found != NULL) && (found == a+i)){
printf("%s\n", a+i);
}
}
return 0;
}
strstr関数について調べてはみたのですが、数を数えるのをどうやって作ればよいか見当もつきません。
説明もお願いします。
次のプログラムの英文の文章の中に冠詞の[the]の数をstrstr関数を使って数えるプログラムを作成する。
thenなどは数えないようにする。
#include <stdio.h>
#include <string.h>
int main(void)
{
int i,len;
char *found;
char a[/url]="Chiba University was founded in 1949, unifying several regional former national colleges and schools such as Chiba Medical College and Chiba Normal School. Its fundamental mission since then has been, as encapsulated by the inscription on the University Bell, ad altiora semper (always toward the higher), to equip students with the ability to make mature and informed judgments while nurturing and guiding their creativity. Pursuing these goals of excellence has resulted in Chiba University becoming one of the leading academic research centers of Japan.";
len = strlen(a);
for(i=0;i<len;i++){
found = strstr(a+i, "the");
if ((found != NULL) && (found == a+i)){
printf("%s\n", a+i);
}
}
return 0;
}