中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

C 練習(xí)實(shí)例99

C 語言經(jīng)典100例 C 語言經(jīng)典100例

題目:有兩個磁盤文件A和B,各存放一行字母,要求把這兩個文件中的信息合并(按字母順序排列),輸出到一個新文件C中。

程序分析:你需要先創(chuàng)建 A.txt 與 B.txt。

A.txt文件內(nèi)容:

123

B.txt文件內(nèi)容:

456

程序源代碼:

實(shí)例

// Created by on 15/11/9. // Copyright ? 2015年 小白教程. All rights reserved. // #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { FILE*fa,*fb,*fc; int i,j,k; char str[100],str1[100]; char tem; if((fa=fopen("A.txt","r"))==NULL) // A.txt 文件需要存在 { printf("error: cannot open A file!n"); exit(0); } fgets(str,99,fa); fclose(fa); if((fb=fopen("B.txt","r"))==NULL) // B.txt 文件需要存在 { printf("error: cannot open B file!n"); exit(0); } fgets(str1,100,fb); fclose(fb); strcat(str,str1); for(i=strlen(str)-1;i>1;i--) for(j=0;j<i;j++) if(str[j]>str[j+1]) { tem=str[j]; str[j]=str[j+1]; str[j+1]=tem; } if((fc=fopen("C.txt","w"))==NULL) // 合并為 C.txt { printf("error: cannot open C file!n"); exit(0); } fputs(str,fc); fclose(fc); system("pause"); return 0; }

以上實(shí)例運(yùn)行輸出結(jié)果后,打開 C.txt 內(nèi)容如下:

123456

C 語言經(jīng)典100例 C 語言經(jīng)典100例

其他擴(kuò)展