Hi guys
One of the things about C that I have also been a little worried about is when using strings. Say that I want to ask the user to input a sentence:
Code:
#include <stdio.h>
#define length 100
int main()
{
int i=0;
char str[length];
while((i < length-1) && (str[i]=getche())!=13)
{
i++;
}
str[i]='\0';
return 0;
}
Perhaps the user only enters a sentence 2 characters long. Now, aren't the other 98 characters just taking up unnecessary space?
What is the closest one can get to dynamically allocate a string in C, such that this waste of memory is not present in a program?
Best,
Niles.