三九宝宝网宝宝教育教学论文

c语言编程:字符串处理

01月07日 编辑 39baobao.com

#include

#include

#include

int sortArr(int *arr, int count)

{

int i = 0, j = 0,tmp;

for (i = 0; i {

for (j = i + 1; j {

if (arr[i]>arr[j])

{

tmp = arr[i];

arr[i] = arr[j];

arr[j] = tmp;

}

}

}

return 0;

}

void main()

{

int rv = 0;

int buf[300] = { 0 };

int count = 0;

int i = 0;

char tmp;

int num=0;

FILE *fp1 = fopen("1.txt","r");

FILE *fp2 = fopen("2.txt","r");

FILE *fp3 = fopen("3.txt", "w+");

if (fp1 == NULL||fp2==NULL)

{

printf("文件打开失败\n");

rv = -1;

goto End;

}

while (!feof(fp1))

{

fscanf(fp1, "%d", &buf[count++]);

}

fclose(fp1);

while (!feof(fp2))

{

fscanf(fp2, "%d", &buf[count++]);

}

fclose(fp2);

sortArr(buf, count);

for (i = 0; i {

fprintf(fp3, "%d\t", buf[i]);

}

fclose(fp3);

End:

system("pause");

}

推荐阅读
图文推荐