Hello all,

I'd first like to say that I'm pretty much a beginner in C, so this and other problems I post may seem trivial to many of you. All I can ask for is patience and forgiveness

Now, on to my problem. For some time now, I have been bugged with the issue of making a "really dynamic array". To be more specific, an array whose size would be defined by the length of the string. If the array content where to be, say "Hello World", the array would be of size [12]. If the content of the array were to be "C", the array would be size [2]. You can always just define a big enough array (something like ar_word[500]; ) but thats just way too...inelegant. Anyway, I had an idea solving this problem that pretty much worked out:

Code:
#include <stdio.h>
#include <string.h>

int main()
{
  int x = 0;                                        /*Will be the size of the array*/
  char word[x];                                     /*The actual array*/
  while ((word[x] = getchar()) != '\n') {           /* User presses a key, the corresponding character is then loaded into word[x]. AFTER that the program determines whether or not "Enter" was pressed*/
	char word[++x];                             /*x is enlarged by one, thus also the array size*/
  }
  word[x]='\0';                                     /*When the loop ends, the last "column" of word has the value of "\n". That is replaced with the value of "\0"*/
  printf("%s",word); 
  return 0;
}

The problem with this code is that the limit is 32. Once you go above 32 characters, the array size goes back to zero (I've strlen'd the array and then compared it to the value of x. While x is 33 or more, the length of "word" is zero). I guess this has something to do with the 32bit environment I'm working in, but then again I'm not sure.

My question: does anyone know how I can get around this? Either that, or does anyone know another whay of making a "really dynamic array"?

Thanks in advance for all help and advice.