gpt4 book ai didi

c - c 中的短函数 - 不明白哪里出了问题

转载 作者:太空宇宙 更新时间:2023-11-04 06:39:31 25 4
gpt4 key购买 nike

我正在编写一个函数,它只计算 DNA 的“互补”链,意思是用 G 替换 C,用 A 替换 T,等等。

这是我写的:

#include <stdio.h>
#include <string.h>
#define SIZE 70

int isLegitSequence(char sequence[]);
void getComplementaryStrand(char complementary[],char sequence[]);
int findSubSequence(char sequence[],char subsequence[]);
int findSubComplementary(char sequence[],char subcomplementary[]);
void cutSequence(char sequence[],char tocut[]);
void checkDNAList(char data[][SIZE],int rows,char sequence[]);


void main(){
char dnaSequence[SIZE];
char compDnaSequence[SIZE];

printf("Enter a DNA Strand\n");
gets(dnaSequence);
printf("%d\n",isLegitSequence(dnaSequence));
getComplementaryStrand(compDnaSequence,dnaSequence);
puts(compDnaSequence);

}

int isLegitSequence(char sequence[]){
int i=0;
while (sequence[i]){
if(sequence[i]=='A'||sequence[i]=='C'||sequence[i]=='G'||sequence[i]=='T');
else return 0;
i++;
}
return 1;
}

void getComplementaryStrand(char complementary[SIZE],char sequence[SIZE]){
int j=strlen(sequence)-1,i;
for(i=0;sequence[i];i++,j--){
if(sequence[i]=='A') sequence[j]='T';
else if(sequence[i]=='C') sequence[j]='G';
else if(sequence[i]=='G') sequence[j]='C';
else sequence[j]='A';
}
complementary[strlen(sequence)]='\0';
}

但是,这是我运行程序时得到的结果:

Enter a DNA Strand
CGCTC
1
╠╠╠╠╠
Press any key to continue . . .

这是我第一次使用函数,所以我不确定我在这里做错了什么。非常感谢帮助,但在我的理解范围内,即非常非常基本。

最佳答案

您需要在调用函数的源文件顶部添加函数 getComplementaryStrand 的原型(prototype)。

在源文件的顶部添加这一行:

void getComplementaryStrand(char complementary[SIZE],char sequence[SIZE]);

编辑:问题在此期间发生了变化……之前是编译错误。 OP 请提出一个新问题,而不是用一个新问题编辑您的原始问题。

关于c - c 中的短函数 - 不明白哪里出了问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10463357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com