gpt4 book ai didi

c - 错误 : -ld returned 1 exit status.

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

#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;
}
}

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

如果我注释函数调用 (cc(a,loc,ch,&num);),它将编译。有什么建议么?这是我的第一门编程类(class),我为此苦思冥想了太久。

注释掉函数调用的输出:

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

最佳答案

你有一个额外的“;”在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;

关于c - 错误 : -ld returned 1 exit status.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36342934/

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