|
发表于 2019-9-26 10:08:33
|
显示全部楼层
本帖最后由 superbe 于 2019-9-26 16:49 编辑
试着编写了一下,看看有没有用。
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- FILE *fpin,*fpout;
- char fin[20],fout[20],ch;
- unsigned int countA=0,countC=0,countG=0,countT=0;
- printf("输入文件名:");
- scanf("%s",fin);
- printf("\n输出文件名:");
- scanf("%s",fout);
- if((fpin=fopen(fin,"r"))==NULL){
- printf("打开输入文件失败!\n");
- exit(-1);
- }
- if((fpout=fopen(fout,"w"))==NULL){
- printf("打开输出文件失败!");
- exit(-1);
- }
- while((ch=fgetc(fpin))!=EOF){
- switch(ch)
- {
- case 'A':
- countA++;
- break;
- case 'C':
- countC++;
- break;
- case 'G':
- countG++;
- break;
- case 'T':
- countT++;
- break;
- }
- }
- fprintf(fpout,"%u %u %u %u",countA,countC,countG,countT);
- fclose(fpin);
- fclose(fpout);
- printf("\nComplete.\n");
- return 0;
- }
复制代码
switch的作用是区分不同的字符A,C,G,T,对它们分别计数。 |
|