QUOTE(shangyi @ 23 Aug, 2008 - 09:57 AM)

QUOTE(KYA @ 23 Aug, 2008 - 09:30 AM)

can you make it a string or do you have to make a char array?
i thought strings consist of character arrays? anyway i need to make a char array. because im learning C right now
C++ has a string class, in C all strings are character arrays.
As for your question about how to make the length of a string dynamic:
In C to make a dynamic sized string is a little difficult. One way is to set a maximum size (say 128 chars) and allocate 128 char that can be used.
char maxLenStr[128];This can hold any string UP TO 127 characters (remember you need a terminating char of 0).
To have truly dynamic abilities you need to use dynamic memory. Generally the way to do this is to allocate a buffer of say 256 chars, and and copy the users input into that buffer (up to 256 chars of users input anyway). Then scroll though and look for a terminating char. If you don't find one, then allocate a larger array and copy the old data into it and release the first, then grab another 256 characters and see if there is a terminting char... if there STILL is not, then again you will have to allocate a larger buffer... you keep this up until you allocate enough memory.
C actually has some functions to help with this kind of thing. realloc will expand the size of your buffer and (if needed) copy over the old info into the new buffer.