简体   繁体   English

错误:-ld返回1个退出状态。

[英]error: -ld returned 1 exit status.

#include <stdio.h> 
#include <wchar.h>
#include <stdlib.h>
#define NR 5 
#define NC 6 
#define NCC 30 
void cc(char arr[][NC],int locations[][2],char ch,int *num); 
int main(){ 
FILE *fPtr; 
char linStr[NC+1]; 
char a[NR][NC]; 
int loc[NCC][2]; 
char ch; 
    int i,j,num; 

printf("lab 4(b) solution by <NAME>\n");


if((fPtr = fopen ("/home/unersame/Desktop/data.dat","r")) == NULL ){
    printf("file data.dat could not be opened\n"); 
}else{ 
    /* file processing follows */ 

    for(i=0;i<NR;i++){
      //fscanf(fPtr, "%c\n",linStr);



      for(j=0; j<NC; j++){
fscanf(fPtr, "%c",&linStr[j]);          
j<NC?a[i][j]=linStr[j]:0;  


}
    } 
    printf("Character array is:\n"); 
        for(i=0;i<NR;i++){
    for(j=0; j<NC; j++){

            printf("%c", a[i][j]);
    }

        } 
puts("");
        printf("Enter character to search for\n");
        scanf("%c",&ch); 
        cc(a,loc,ch,&num); 
        printf("The character %c occurred %d times\n",ch,num); 
        printf("The (row,column) index pairs for the locations of\n"); 
        printf("the character %c follow:\n", ch); 
        for(i=0;i<num;i++){ 
            printf("(%d,%d)\n",i,j);
            fclose(fPtr);
    } 
    return 0;
} 
void cc(char a[][NC], int locations[NCC][2], char ch, int *num){
    int i,j,k;

    k=0;

      for(i=0; i<NR; i++){
          for(j=0; j<NC; j++){
            //scanf("%c", &a[i][j]);

    if(a[i][j]==ch?locations=loc:0){
           locations[k][0]=i;
           locations[k][1]=j;

            *num=k;
             k++; 

                        }


                           }
//*num=k;
}



//*num=k;
}
}

Console output: unersame@ubuntu:~$ gcc -o 42b /home/unersame/Desktop/42b.c /tmp/cctIyUei.o: In function main': 42b.c:(.text+0x1fe): undefined reference to cc' collect2: error: ld returned 1 exit status 控制台输出:unersame @ ubuntu:〜$ gcc -o 42b /home/unersame/Desktop/42b.c /tmp/cctIyUei.o:在main': 42b.c:(.text+0x1fe): undefined reference to函数中main': 42b.c:(.text+0x1fe): undefined reference to cc的main': 42b.c:(.text+0x1fe): undefined reference to 'collect2:错误:ld返回1退出状态

If I comment the function call (cc(a,loc,ch,&num);) it will compile. 如果我注释函数调用(cc(a,loc,ch,&num);),它将进行编译。 Any suggestions? 有什么建议么? This is my first programming course and Ive been beating my head over this for far too long. 这是我的第一门编程课程,而我为此一直都在努力。

Output with function call commented out: 函数调用已注释掉的输出:

Character array is:
231456 
s3fgtr 
wer56t 
1233gh
Enter character to search for
3
The character 3 occurred 32766 times
The (row,column) index pairs for the locations of
the character 3 follow:
(0,6)
(1,6)
*** Error in `./42b': double free or corruption (top): 0x0000000000bc2010 ***
Aborted (core dumped)
unersame@ubuntu:~$ gcc -o 42b /home/unersame/Desktop/42b.c -std=c99
/tmp/ccl8WvHf.o: In function `main':
42b.c:(.text+0x1f1): undefined reference to `cc'
collect2: error: ld returned 1 exit status

You have an extra ";" 您还有一个额外的“;” in cc function definition: cc函数定义中:

void cc(char a[][NC], int loc[NCC][2], char ch, int *num); {
    int i,j,k,loc[NCC][2],num;
    char ch, arr[NR][NC];
    k0;

You have a semicolon after your function declaration here: 您在此处进行函数声明后有分号:

void cc(char a[][NC], int loc[NCC][2], char ch, int *num); {

Which is causing it to be a declaration, and not a definition of the function. 这导致它成为函数的声明,而不是函数的定义。 I believe that removing that semicolon should make the linker error go away, but frankly it's hard to tell; 我相信删除该分号应该可以使链接程序错误消失,但是坦率地说,这很难说。 you'll have an easier time of it if you keep your code properly formatted and indented. 如果您对代码进行适当的格式化和缩排,则可以轻松地完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM