【发布时间】:2013-11-27 03:55:26
【问题描述】:
我正在处理 DNA 链,因此输入字符串将类似于:ATGC(可能的碱基 A、T、G 和 C)
我必须利用这个函数:void updateGCCount(char s[], int * gc, int * at) 来计算输入字符串中“GC”内容的百分比。
函数 updateGCCount 扫描输入字符串 s 的内容,并适当地更新“GC”和“AT”计数。
我不明白的是,如果这个函数没有返回任何东西,如果它是无效的,那么我如何使用它来计算“GC”内容的百分比?
这是我的 updateGCCount 函数代码:
void updateGCCount(char s[], int * gc, int * at){
int i;
for(i=0;i!='\0';i++){
if(s[i]=='G' || s[i]=='C'){
(*gc)++; /*Updated with the help of people who answered!*/
}
if(s[i]=='A' || s[i]=='T'){
(*at)++; /*Updated with the help of people who answered!*/
}
}
}
现在这是我调用上述函数的主要函数(在收到以下答案的帮助后添加了此代码):
int main(){
char s[400];
int gc, at;
double percentage;
scanf("%s", s);
gc = 0;
at = 0;
updateGCCount(s, &gc, &at);
percentage = (gc * 100.0)/(strlen(s) - 1);
printf("Sequence : %s\n", s);
printf("GC-content: %.2f\n", percentage);
return 0;
}
我遇到的问题! 当我输入“ATCG”的输入字符串时,百分比为 0,这是不正确的,我无法弄清楚为什么它会给我这个问题!非常感谢您的帮助!
谢谢!
【问题讨论】:
-
gc++和at++递增指针 -
那么,如果这增加了指针,在主函数中,我是否必须使用 for 循环来遍历输入字符串,然后在 for 循环中,我会调用 updateGCCount 吗?
标签: c