あるテキストを辞書順にソートし、別のテキストに出力するプログラムを作成したいです。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char buff[10000];
char *data[10000];
char *create_string(char *x)
{
char *p;
p=malloc(strlen(x)+1);
strcpy(p,x);
return p;
}
void copyfile(FILE *is,FILE *os)
{
int a=0;
while(fscanf(is,"%s\n",buff)!=EOF)
{
data[a]=create_string(buff);
fprintf(os,"%s\n",data[a]);
a++;
}
return;
}
int main(void)
{
FILE *is,*os;
is=fopen("tom.txt","r");
if(is==0)
{
printf("ERROR");
return 0;
}
os=fopen("new.txt","w");
if(os==0)
{
printf("ERROR2");
return 0;
}
copyfile(is,os);
fclose(is);
fclose(os);
return 0;
}
このプログラムのcopyfileの部分にポインターをソートする機能を追加したいのですがわかりません
ソート方法はバブルソートです
(上で”あるテキスト”と書いたテキスト内には大文字と小文字があるので入力したときに全部小文字にして区別したいです)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。