array error

at the line 7: [Error] array bound is not an integer constant before '[' token

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

char risp[7],risp1[2],risp2[2],risp3[2],s[2];
int n,i;
int v[n];

int main(){
	printf("Pensa ad un numero intero da 1 a n in cui n e' ");
	scanf("%d",&n);
	printf("\nOra provero' ad indovinarlo!");
	//Dopo aver ottenuto n scrivo i numeri nel vettore v
	for(i=0; i<n; i++){
		v[i]=i+1;
		printf("%d\n",v[i]);
	}
}
Last edited on
When you define an array the size need to be a compile-time constant.
Have you got into the habit of non-const sized arrays from using the GCC compiler?

GCC is rather naughty as by default it allows you to use non-const arrays sizes when compiling C++ code. This extension comes from C99, where it's perfectly legal.

Andy
Topic archived. No new replies allowed.