C/C++の宿題を片付けます 87代目
at TECH
92:デフォルトの名無しさん
07/05/15 16:19:25
>>53
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct word word;
struct word{
char *en;
char *jp;
word *next;
};
word *makenode(FILE *fp);
void search(word *temp);
void mfree(word *temp);
int main()
{FILE *fp = fopen("ta.doc","r");word *temp = makenode(fp);show(temp);search(temp);
mfree(temp);return 0;}
word *makenode(FILE *fp){ word *temp = NULL;word *now = NULL;char *ctemp;
char buff[256] = {'\0'};char en[256] = {'\0'};char jp[256] = {'\0'};
while(fgets(buff,sizeof(buff), fp)){if(ctemp = strchr(buff, '\n'))*ctemp = '\0';
if(ctemp = strchr(buff, ','))*ctemp = '\0';
strcpy(en, buff);strcpy(jp, ctemp + 1);temp = malloc(sizeof(word));temp->en = malloc(strlen(en) + 1);
temp->jp = malloc(strlen(jp) + 1);strcpy(temp->en, en);strcpy(temp->jp, jp);
if(now == NULL){ temp->next = now;now = temp;}else{now->next = NULL;temp->next = now;
now = temp;}}return now;}void search(word *temp){ char buff[256] = {'\0'};word *wtemp;
char *ctemp;for(;;){puts("英和辞典");printf("英単語:");fgets(buff, sizeof(buff),stdin);
if(ctemp = strchr(buff, '\n'))*ctemp = '\0';if(strcmp(buff,"q") == 0)break;
for(wtemp = temp; wtemp != NULL; wtemp = wtemp->next)if(strcmp(buff, wtemp->en) == 0)
printf("日本語で「%s」\n",wtemp->jp);}}void mfree(word *temp){word *wtemp = temp;word *wftemp = NULL;
char *cjtemp = NULL;char *cetemp = NULL;while(wtemp != NULL){wftemp = wtemp;cjtemp = wtemp->jp;
cetemp = wtemp->en;wtemp = wtemp->next;free(cjtemp);free(cetemp);free(wftemp);}}
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
4258日前に更新/299 KB
担当:undef