[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [linuxiran] [OT] C programming, variable size array
From: |
Hossein S. Zadeh |
Subject: |
Re: [linuxiran] [OT] C programming, variable size array |
Date: |
Sat, 13 Dec 2003 17:00:34 +1100 (EST) |
On Fri, 12 Dec 2003, Aryan Ameri wrote:
> int tmp, cnt = 0;
> static int arr[cnt];
> printf( "Enter Number\n");
> scanf( "%d", &tmp);
> while ( (tmp = getchar() ) != EOF ) {
> arr[cnt] = tmp;
> cnt += 1;
> static int arr[cnt];
> printf( "Enter Number\n");
> scanf( "%d", &tmp);
> }
>
> return 0;
> }
>
> This sounded logical to me. But the compiler (gcc 3.2) gives me a syntax
> error saying that 'storage size of 'arr' isn't constant'. Well, I don't
> want it to be constant!
Hi there,
This is obviously wrong. Array sizes are needed (by C compilers) during
compile time. This is the single most cause of buffer overflows in C and
C++ programs.
What you need is a "linked list". You can find examples in any C book you
find in your nearest book shop or library.
cheers,
Hossein
- Re: [linuxiran] [OT] C programming, variable size array, (continued)
Re: [linuxiran] [OT] C programming, variable size array, Arash Partow, 2003/12/12
- Re: [linuxiran] [OT] C programming, variable size array, Aryan Ameri, 2003/12/12
- Re: [linuxiran] [OT] C programming, variable size array, Arash Partow, 2003/12/12
- Re: [linuxiran] [OT] C programming, variable size array, Kaveh Mousavi, 2003/12/12
- Re: [linuxiran] [OT] C programming, variable size array, Mohammad Reza Ghorbani, 2003/12/13
- Re: [linuxiran] [OT] C programming, variable size array, Arash Partow, 2003/12/13
Re: [linuxiran] [OT] C programming, variable size array,
Hossein S. Zadeh <=