C/C++の宿題を片付けます 62代目
■ このスレッドは過去ログ倉庫に格納されています
0578575
2006/03/15(水) 07:29:31あれば、何行目と単語が表示するようなプログラムにしかならんかった
#include <stdio.h>#include <string.h>#include <stdlib.h>
typedef struct List{char letter[30];intgyou;struct List *next;}List;
void Fluss(List *p_fluss);void Getword(List *p_get);int main(void)
{char in_word_buff[30];int i = 1;char *gDlim ="\n",*pass;List *p_root = NULL;FILE *Dictionary;
List *p_new;List *p_fluss;if((Dictionary = fopen("辞書ファイル.txt","r")) == NULL){
fprintf(stderr,"ファイルを開けない");exit(1);}
while((fgets(in_word_buff,sizeof(in_word_buff),Dictionary)) != NULL){
p_new = (List *)malloc(sizeof(List));if(p_new == NULL){
fprintf(stderr,"メモリ確保出来ず");exit(1);}
pass = strtok(in_word_buff,gDlim);p_new->gyou = i++;
strcpy(p_new->letter,pass);p_new->next = p_root;p_root = p_new;}
p_fluss = p_root;Getword(p_fluss);Fluss(p_fluss); return 0;}
void Fluss(List *p_fluss){List *fl,*temp;int i = 1;for(fl = p_fluss ;fl!= NULL;){temp = fl->next;
free(fl);fl = temp;}}void Getword(List *p_get){
int get,i;char buff[256] = {0};printf("検索する単語はいくつですか");fgets(buff,sizeof(buff),stdin);
sscanf(buff,"%d",&get);for(i=1; i<=get;i++){printf("検索する単語%d個目\n",i);fgets(buff,sizeof(buff),stdin);
sscanf(buff,"%s",buff);while(1){if(p_get == NULL) break;if(0 == strcmp(p_get->letter,buff))
printf("%sは%d行目にあります\n",p_get->letter,p_get->gyou);p_get = p_get->next;}}}
■ このスレッドは過去ログ倉庫に格納されています