DIGIT-ARC read-only archive · snapshot: July 23, 2026

Array in c problem

3 posts · originally from https://geek.digit.in/community/threads/array-in-c-problem.148075/

Gauravs90
Gauravs90 Original post #1
Oct 27, 2011 at 11:51 AM
I'm using windows 7 64-bit and codeblocks mingw for compiling the following program

Code:
#include<stdio.h>

int main()
{
    int i,len,a[100];
    printf("enter the no. of elements\n");
    scanf("%d",&len);
    printf("enter the integers\n");
    for(i=0;i<len;i++)
    scanf("%d",a[i]);
    printf("integers entered are");
    for(i=0;i<len;i++)
    printf("\n%d",a[i]);
}

It compiles successfully, but when i run the generated exe file it fails at the step when i try to enter some no. in array... how can i fix it...
S
Oct 27, 2011 at 12:00 PM
You forgot to take the address of each array item in your second scanf().

Code:
scanf("%d",a[i]);

should be

Code:
scanf("%d",[B]&[/B]a[i]);
Gauravs90
Oct 27, 2011 at 12:23 PM
oops!!!! silly mistake on my part....