Suppose the user wants to input a string. The length of the string is unknown. I also don't want a character array of size 1000 or what so ever. I want the size of the character array increasing by 1 byte for every character entered. Here is a sample output :
Enter String : ABCDEFGH
Length of the String : 8
Size of the String : 8 bytes
Some other conditions
- The whole string will be entered at once. Not "one character entered, hit enter, then next character"
- Terminating condition : newline
I was thinking of the algorithm. It could be something like this
int infinite_input()
{
do
{
create new address for character
if(new address == NULL)
return 0; // denoting failure of function
input character
store character at new address
if(previous address != NULL)
previous address will point to new address
echo character // if input does not echo
store new address in 'previous' // make new address as previous address
increase size of string by 1
}while(character != '\n');
point new address to NULL
return size of string;
}
My main problem is with the input