gpt4 book ai didi

c - main/error :expected ';' , ',' or ')' before numeric constant|中的函数的隐式声明

转载 作者:行者123 更新时间:2023-12-03 07:38:09 24 4
gpt4 key购买 nike

#include <stdio.h>
#include <stdlib.h>
#include "simpio.h"

#define cols 10
#define rows 10

void populate_data(int rows,int cols,int A[rows][cols],int R,int C);
void print_array(int rows,int cols,int A[rows][cols],int R,int C);
void change_array(int rows,int cols,int A[rows][cols],int R,int C);

int main(){

int R,C,A[rows][cols];

/*Eisagwgh twn grammwn/sthlwn*/
printf("Dwse ton arithmo twn grammwn: ");
R=GetInteger();
printf("Dwse ton arithmo twn sthlwn: ");
C=GetInteger();

populate_data(rows,cols,A,R,C);
printf("ARXIKOS PINAKAS");
print_array(rows,cols,A,R,C);
change_array(rows,cols,A,R,C);
printf("ALLAGMENOS PINAKAS");
print_array(rows,cols,A,R,C);

return 0;

}


void populate_data(int rows,int cols,int A[rows][cols],int R,int C){

int i,j;

for (i=0; i<R; i++){
for (j=0; j<C; j++){
A[i][j]=rand()%100;
}
}

}
void print_array(int rows,int cols,int A[rows][cols],int R,int C){

int i,j;

for (i=0; i<R; i++){
printf("\n");
for (j=0; j<C; j++){
printf("%d",A[i][j]);
}
}
}
void change_array(int rows,int cols,int A[rows][cols],int R,int C){

int i,j,index,max;

for (i=0; i<R; i++){
max=A[i][0];
index=0;
for (j=1; j<C; j++){
if (A[i][j]>max){
max=A[i][j];
index=j;
}
}
for (j=0; j<index; j++){
A[i][j]=max;
}
}

}
因此,我只是为大学的一个项目编写了此代码。当我编译它时,它说“函数的隐式声明”,但是发生错误的行是这些:“populate_data(rows,cols,A,R,C);
print_array(rows,cols,A,R,C);
在#define行上也说“error:expected';',',','或')'在数字常量|。之前。“这是什么意思?

最佳答案

colsrows预处理程序常量与colsrows变量冲突。您不能为两者使用相同的名称。预处理程序将所有出现的内容替换为10,从而产生此语法无效的代码:

void populate_data(int 10,int 10,int A[10][10],int R,int C);
void print_array(int 10,int 10,int A[10][10],int R,int C);
void change_array(int 10,int 10,int A[10][10],int R,int C);
我建议对预处理器宏始终使用大写字母。这是C语言中的规范,以便清楚地知道哪些标识符是宏。
#define COLS 10
#define ROWS 10

关于c - main/error :expected ';' , ',' or ')' before numeric constant|中的函数的隐式声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65206131/

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