|
皆さんのおかげでどうにか形にしたのですが上手く行きません
何処がわるいのでしょか?何が悪いか分からないため先に進めません(泣)
#include<stdio.h>
#include<ctype.h>
char *search(char *,char *);
int main(void)
{
FILE *fp;
char *key;
char *p;
char buf[1024];
char line[1024];
char lin[1024];
int i,b,c;
int d=1;
int e=1;
int a = 0;
fp = fopen("text.txt","r"); /*ファイルオープン*/
while(fgets(buf,sizeof(buf),fp) != NULL){ /*ファイルの文字を配列に代入*/
if(e==1){
key = strtok(buf,"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~\n\t\v\f\r "); /*文字区切り*/
strncpy(line, key, 128);
p=search(buf,line);
while (p!=NULL){
if(d==1){
printf("%s:",p);
d++;
}
printf("*");/*ヒストグラムに*を表示*/
p=search(p+strlen(line),line);
}
}
printf("\n");
d=1;
e=2;
key = strtok(NULL,"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~\n\t\v\f\r ");
strncpy(line, key, 128);
p=search(buf,line);
while (p!=NULL){
if(d==1){
printf("%s:",p);
d++;
}
printf("*");/*ヒストグラムに*を表示*/
p=search(p+strlen(line),line);
}
printf("\n");
}
fclose(fp);/*ファイルを閉じる*/
}
char *search(char *buf,char *line)/*文字列の照合関数*/
{
int m,n;
char *p;
m=strlen(buf);
n=strlen(line);
for(p=buf;p<=buf+m-n;p++){
if(strncmp(p,line,n)==0)
return p;
}
return NULL;
}
|