70,037
社区成员
发帖
与我相关
我的任务
分享#include <stdio.h>
#include <malloc.h>
#include <string.h>
void main()
{
char ch,temp;
FILE *fp1,*fp2;
long n=0,i=0;
fp1 = fopen("C:\\Documents and Settings\\Rui.2B9F317BD5854FF\\桌面\\example\\A.txt","r");
fp2 = fopen("C:\\Documents and Settings\\Rui.2B9F317BD5854FF\\桌面\\example\\B.txt","w");
if(!fp1 || !fp2)
{
return;
}
while(fgetc(fp1) != EOF) //统计A文件中字符数
{
n++;
}
char *str=(char *)malloc((n * sizeof(ch)) + 1); //给str分配足够的内存空间
strcpy(str,"");
rewind(fp1);
while((ch = fgetc(fp1)) != EOF) //进行AT,CG互换
{
str[i] = ch;
if(ch == 'A') str[i] = 'T';
if(ch == 'T') str[i] = 'A';
if(ch == 'C') str[i] = 'G';
if(ch == 'G') str[i] = 'C';
i++;
}
str[i]= '\0';
for(i = n - 1;i != -1;i--) //将str逆序写入B文件中
{
fputc(str[i],fp2);
}
free(str);
fclose(fp1);
fclose(fp2);
}
#include <stdio.h> #include <stdio.h>