所以当我尝试调试我的程序时,我遇到了这些警告,我不知道如何处理。这是编译器给我的内容:
translate.c: In function 'main':
translate.c:65: warning: passing argument 2 of 'strncmp' makes pointer from integer without a cast
/usr/include/string.h:146: note: expected 'const char *' but argument is of type 'char'
translate.c:67: warning: passing argument 1 of 'strcpy' makes pointer from integer without a cast
/usr/include/string.h:128: note: expected 'char * __restrict__' but argument is of type 'char'
translate.c:88: warning: passing argument 1 of 'strcpy' from incompatible pointer type
/usr/include/string.h:128: note: expected 'char * __restrict__' but argument is of type 'struct node *'
translate.c:100: warning: format '%s' expects type 'char *', but argument 3 has type 'struct node *'
这是我的代码,我会评论它所指的区域:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node{
char seq[300];
struct node* next;
} NODE;
int
main(int argc, char* argv[]){
int i, j=0;
FILE *fin, *fout, *fop;
char code1[100], code2[100], prot1[2], prot2[4];
NODE *current, *first, *prev;
fin = fopen( argv[1], "r");
fout = fopen( argv[2], "w");
fop = fopen("codeoflife.txt", "r");
code2[0] = '\0';
current = first = malloc (sizeof (NODE));
while( fscanf( fin, "%s", current -> seq) != EOF) {
for (i = 0; i < 300; i++){
if (current->seq[i] == 'a')
current->seq[i] = 'A';
else if (current->seq[i] == 't')
current->seq[i] = 'T';
else if(current->seq[i] == 'g')
current->seq[i] = 'G';
else if(current->seq[i] == 'c')
current->seq[i] = 'C';
}
if ( (current -> next = malloc ( sizeof(NODE) ) ) == NULL){
fprintf(fout, "Out of memory\nCan't add more DNA sequences\n");
return EXIT_FAILURE;
}
prev = current;
current = current -> next;
}
fclose(fin);
current = first;
while(current->next != NULL){
for( i = 0; i < 300; i++){
if( current->seq[i] == 'A')
if( current->seq[i+1] == 'G')
if( current->seq[i+2] =='T'){
i = i+3;
j = 0;
code1[j] = 'M';
while(fscanf(fop, "%s%s", prot1, prot2) != EOF){
if(strcmp(prot2, "TAA") == 0 || strcmp(prot2, "TAG") == 0 || strcmp(prot2, "TGA") == 0){
fclose(fop);
break;
}
/* line 65 */ if(strncmp(prot2, current->seq[i], 3) == 0){
j++;
/* line 67*/ strcpy(code1[j], prot1);
fclose(fop);
i = i + 3;
}
}
if(strcmp(code1, code2) > 0)
strcpy(code2, code1);
//else if (strcmp(code1, code2) < 0)
}
}
if(strcmp(prot2, "TAA") != 0 && strcmp(prot2, "TAG") != 0 && strcmp(prot2, "TGA") != 0){
strcpy ( current->seq, "None");
current = current->next;
continue;
}
/* line 88 */ strcpy(current->next, code2);
current = current->next;
code2[0] = '\0';
}
free(current);
prev->next = NULL;
current = first;
while(current->next != NULL){
/* line 100 */ fprintf( fout, "\n%s\n", current->next);
current = current->next;
}
return 0;
}
请帮助我理解这一点。
答案 0 :(得分:4)
current->seq
为char[]
(即const char *
),因此current->seq[i]
为char
。
如果您打算使用strncmp
来比较以current->seq
字符开头的i
内容,请将其调用为strncmp(xxx, current->seq+i, N)
(例如strncmp(prot2, current->seq+i, 3)
答案 1 :(得分:2)
或许,您需要获取字符串字符的地址,而不是字符,并进行某种类型的转换:
65: strncmp(prot2, ¤t->seq[i], 3)
67: strcpy(&code1[j], prot1)
88: strcpy((char *)current->next, code2)
100: fprintf( fout, "\n%s\n", (char *)current->next);