• + 1 comment

    Hello, Thanks a lot for replying. It has indeed helped me. Whatever you've explaned has added to my knowledge of the programming world and I will make the most of it.

    However I looked up on the internet for my problem of dynamically allocating memory for inputString during run time and I'm happy to say that my problem is solved. Now, I can input a string of any length I want and the code will allocate only that much memory which is required to store that length of string which I input, not more not less.

    The reason why I wanted to do this is because if we reserve only a fixed memory like in your code : BUFSIZ, the programm is not flexible or expandable. Also we have no idea as to what length of string the user is going to enter. Suppose the user entered a string whose length is very short as compared to BUFSIZ than we are wasting a lot of memory. Memory which we don't even need.

    Also, I tried to run your code but I think in place of EOF it should be '\n' because EOF looks for end of file whereas \n looks for new line. If we use only EOF, the loop will never end because it never sees the end of file because when we typed a string in the command line and hit enter, we actually added a new line at the end of the string. The programm sees "hitting enter" as new line. However if we still want the loop to end using EOF we can force it to see a end of file using "Ctrl+D".

    Thanks again. I hope whatever I've said I made sense :)