c - 错误 :declaration terminated incorrectly

标签 c arrays

<分区>

#include<stdio.h>
#include<conio.h>

void insert(int arr[]);

# define LEN 10

int count;

void main(void)
{
  clrscr();
  int arr[]={20,21,22,23,24};
  insert(arr);
  getch();
}

void insert(int arr[])
{
  if(size==count)
    printf("no space");
    return;

  int index,value;
  printf("enter index and value");
  scanf("%d %d",index,value);
  for(int i=count-1;i>=index;i--)
  {
    arr[i+1]=arr[i];
    arr[i]=value;
    count++;
  }
  printf("insert succcess");

}

最佳答案

此行中的分号不正确:

void main(void);

你在这一行忘记了一个分号:

 arr[i=1]=arr[i]

您的代码还有其他错误。例如,这个:

 if(size==count)
 printf("no space");
 return;

总是返回。它相当于:

 if(size==count) {
   printf("no space");
 }
 return;

这是一个很好的例子,说明为什么您应该养成正确缩进代码的习惯,并养成对条件使用大括号的习惯。

此外,size 尚未在任何地方声明。最后,这个:

 scanf("%d %d",index,value);

不会做你想做的事。您需要为 scanf 指针提供您想要存储值的整数,而不是这些整数的值。

关于c - 错误 :declaration terminated incorrectly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3830359/

相关文章:

c - 操作系统(Unix)中的新进程创建

c++ - 我怎样才能让位域以正确的顺序排列我的位?

c - 程序集字符*链接

javascript - replaceChild() 移动图像仅在 javascript 中运行一次

Python:检查对象是否不是 "array-type"

c - 为什么这个程序在多个进程初始化时会卡住?

c - 反转字符串数组

arrays - 使用哈希表检查数组中是否有重复项

javascript - 遍历二维数组并找到 "enclosed rooms"

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP