AB中我输入的是字符怎么用c语言打开文件后是这样的
file:///C:\Users\Administrator\AppData\Roaming\Tencent\Users\1226259926\QQ\WinTemp\RichOle\5%C9U]ZGJ{){LL]RJ%C43YV.jpg#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
FILE *fp1,*fp2,*fp3 ;
int i , j , n , k ;
char c , t , ch ;
if((fp1 = fopen("G://A.txt" , "r" )) == NULL)//if(fp = fopen("A" , "r" ) == NULL)错!
{
printf("can not open the file\n");
exit(0) ;
}
printf("\nfile A:\n");
for(i = 0 ; ch!= EOF ; i ++)
{
ch = fgetc(fp1);
c = ch ;
putchar(ch) ;
}
fclose(fp1);
k = i ;
if((fp2 = fopen("G://B.txt" , "r")) == NULL)
{
printf("can not open the file\n");
exit(0);
}
printf("\nflie B:\n");
ch = fgetc(fp2);
for(i = k-1 ; ch != EOF ; i ++)
{
c = ch ;
putchar(ch);
ch = fgetc(fp2);
}
fclose(fp2);
n = i ;
/*
for(i = 0 ; i < n ; i ++)
for(j = i + 1 ; j < n ; j ++)
if(c > c)
{
t = c ;
c = c ;
c = t ;
}
*/
printf("\nfile C:\n");
fp3 = fopen("C.txt" , "w");
for(i = 0 ; i < n ; i ++)
{
fputc(c , fp3);
putchar(c) ;
}
fclose(fp3);
printf("\n");
}我将你代码的排序部分注视了。具体修改你还是对照下吧,不清楚的地方回复我 请把AB文件的原内容贴一下 sidfate 发表于 2014-4-25 16:23 static/image/common/back.gif
请把AB文件的原内容贴一下
A是ABCB里面是znmcv sidfate 发表于 2014-4-25 16:23 static/image/common/back.gif
请把AB文件的原内容贴一下
//有两个磁盘文件“A”“B”,各存放一行字母,要求把这两个文件的信息合并(按字母顺序排列),输出到一个新文件“C”中
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
FILE *fp ;
int i , j , n , k ;
char c , t , ch ;
if((fp = fopen("G://A.txt" , "r" )) == NULL)//if(fp = fopen("A" , "r" ) == NULL)错!
{
printf("can not open the file\n");
exit(0) ;
}
printf("\nfile A:\n");
for(i = 0 ; (ch = fgetc(fp) != EOF) ; i ++)
{
c = ch ;
putchar(ch) ;
}
fclose(fp);
k = i ;
if((fp = fopen("G://B.txt" , "r")) == NULL)
{
printf("can not open the file\n");
exit(0);
}
printf("\nflie B:\n");
for(i = k ; (ch = fgetc(fp) != EOF) ; i ++)
{
c = ch ;
putchar(ch);
}
fclose(fp);
n = i ;
for(i = 0 ; i < n ; i ++)
for(j = i + 1 ; j < n ; j ++)
//if(strcmp(c , c) >= 0)
if(c > c)
{
t = c ;
c = c ;
c = t ;
}
printf("\nfile C:\n");
fp = fopen("C.txt" , "w");
for(i = 0 ; i < n ; i ++)
{
fputc(c , fp);
putchar(c) ;
}
fclose(fp);
printf("\n");
}
sidfate 发表于 2014-4-25 17:18 static/image/common/back.gif
大神,我爱你!我还有一个问题,你顺带帮我看看吧 学习了!《,,,,,,,,
页:
[1]