tags:

views:

46

answers:

2
#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");

}
+2  A: 

Compile with C99 or GNU extensions.

-- or --

Place your declarations before any statements or expressions.

leppie
+1 for explaining his error...
Nix
+6  A: 

You have an incorrect semicolon on this line:

void main(void);

and you forgot a semicolon on this line:

 arr[i=1]=arr[i]

Your code also has other errors. For example, this:

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

will always return. It is equivalent to:

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

and is a good example of why you should get in the habit of indenting your code properly and get in in the habit of using braces for conditionals.

Additionally, size has not been declared anywhere. And finally, this:

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

isn't going to do what you want. You need to give scanf pointers to the integers you want to store the values in, not the values of those integers.

Tyler McHenry
I saw that as well when i was indenting... +1 (missing {})
Nix
Spotted that too :)
leppie
And your declaring variables many a times in the code,you can only declare a data type once in every {}
fahad
@fahad I'm not sure what you're referring to there. I don't see any variable declared twice.
Tyler McHenry
the declaration within the for loop will be giving an error as she is using a turbo C compiler
fahad
If this program were being compiled as C89, every single variable declaration in it (except `count`) would be an error, since none of them are at the top of their function. If it were being compiled as C99, all of them would be legal. I don't know how you know she is using Turbo C, or which C standard it supports, but in any case I still don't understand how that at all relates to declaring variables twice.
Tyler McHenry
Well every variable except the global variable count will be giving error,if she had declared the variable size in main then (which should be done)then there will be allocation twice.
fahad