#include<stdio.h> int bubble(char array[],int n) {int i,s; char k; for(i=n;i>0;i--) for(s=0;s<i-1;s++) if(array[s]>array[s+1]){k=array[s];array[s]=array[s+1];array[s+1]=k;} }
main() {FILE *in,*out; char ch,infile[100],outfile[100],array[100]; int n=0,m=1; printf("Enter the infile name:\n"); scanf("%s",infile); printf("Enter the outfile name:\n"); scanf("%s",outfile); if((in=fopen(infile,"r"))==NULL) {printf("cannot open input file!\n"); exit(0);} if((out=fopen(outfile,"w"))==NULL) {printf("cannot open output file!\n"); exit(0);} ch=fgetc(in); while(ch!=EOF) {array[n]=ch;n++;ch=fgetc(in);} bubble(array,n); ch=array[0]; while(ch!=EOF) {fputc(ch,out);ch=array[m];m++;} fclose(in); fclose(out); }
运行之后打开,shuchu.c文件,总是会在结果后面多出莫名其妙的字符……:(
[此贴子已经被作者于2004-05-11 16:40:58编辑过]