ぼるじょあがC/C++の宿題を片づけますYO! 68代目at TECH
ぼるじょあがC/C++の宿題を片づけますYO! 68代目 - 暇つぶし2ch890:ぼるじょあ ◆yBEncckFOU
08/05/27 21:36:09
>>886
(・3・) エェー ほらYO!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct tag_list_t{
int num;
char **wordlist;
}list_t;
int list_add(list_t *list, char *word){
int i;
for(i=0;i<list->num;i++) if(strcmp(list->wordlist[i], word)==0) return 0;
list->wordlist=realloc(list->wordlist, sizeof(char*)*(list->num+1));
list->wordlist[list->num]=strdup(word);
list->num+=1;
return 1;
}
int main(void){
list_t list={0, NULL};
char fname_in[FILENAME_MAX], fname_out[FILENAME_MAX], word[255+1];
FILE *fp_in, *fp_out;
printf("”ファイル名は?”");
scanf("%s", fname_in);
printf("”作成先は?”");
scanf("%s", fname_out);
if((fp_in=fopen(fname_in, "r"))==NULL) return 1;
if((fp_out=fopen(fname_out, "w"))==NULL) return 2;
while(fscanf(fp_in, "%255s", word)==1) if(list_add(&list, word)) fprintf(fp_out, "%s\n", word);
fclose(fp_in);
fclose(fp_out);
return 0;
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch