#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): undefined reference to
C-C」 collect2は:エラー:ldは1を返し終了ステータスエラー:-ldが1の終了ステータスを返しました。
私が関数呼び出し(cc(a、loc、ch、& num);)にコメントすると、コンパイルされます。助言がありますか?これは私の最初のプログラミングコースであり、私はこれ以上私の頭を打ち負かされてしまった。
関数呼び出しコメントアウトして出力:
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)
[email protected]:~$ 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
'cctlyUei.o'で' cc() 'が呼び出された場合は、プログラムパラメータの順に' 42b.c' *の後に* 'cclyUei.o'を指定する必要があります。 – EOF
あなたはELI5できますか? cctlyUei.oとは何ですか? – user224202
コードを書式設定してください。 –