注:问题已被编辑,以解决问题。
我编写了这段代码来使用函数反转数组。但是,在第24行中有一个错误,即“预期的”。我读了一遍又一遍,但找不到错误。谁能把它露出来告诉我怎么把它拿掉吗?
#include<stdio.h>
#include<conio.h>
#define max 5
/*function prototype*/
void reverse(int[],int);
void main()
{
int arr[max]={1,2,3,4,5};
int i,j;
clrscr();
printf("the list before reversing:\n");
for(i=0;i<max;i++)
printf("%d",arr[i]);
reverse(arr,max);
printf("\n the list after reversing:\n");
for(i=0;i<max;i++)
printf("%d",arr[i]);
getch();
}
/*function for reversing elements of array*/
void reverse(int num[],int max)
{
int i,j,temp;
for(i=0,j=max-1;i<max/2;i++,j--)
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}发布于 2011-07-12 09:19:26
max被定义为宏。所以经过预处理后,它变成
void reverse(int num[],int 5)这是无效的,您将得到' ) expected'。如果max是常数,那么就不需要将它作为参数传递。而且函数中也缺少一个for。
发布于 2011-07-12 09:12:22
您似乎在for的循环头中缺少了reverse()关键字。
发布于 2011-07-12 09:11:09
编辑:好吧,好吧,我的第一个回答是愚蠢的.(回答时没有充分考虑)
现在我明白了:
问题是
#define max 5稍后使用max (=5)作为参数!
https://stackoverflow.com/questions/6661819
复制相似问题