• [deleted]
    + 1 comment

    "(…) how should the programm save enough space for the string[?]"

    When it comes to C you should make certain constraints. Fortunately, C offers you a BUFSIZ constant. On 32-bit systems it's 512, on 64-bit systems it's 8192. Knowing it and knowing about functions like setbuf or working on input being cut into chunks of some preset length is usually a good idea.

    In general C is used for specialised tasks. You don't need to do some fancy work to read for example a name or phone number, both of those can be fairly reasonably assumed to be well under BUFSIZ. And while it's possible to handle unknown inputs, it's tricky and in some cases simply better handled by turncating everything above some limit. It's not proper, but there's no real need to reinvent the wheel. On Unix systems (or Windows with MinGW set of tools and libraries) you would just use something like GNU readline library and be done with it.

    I can help you and walk you through the code if you would like me to do it. I'm mainly using Haskell and Python but C isn't some dark art for me. ;)

    Also, please don't read my above remark as dismissive. I'm all for people learning it, but C-strings are a hellish subject. If it wasn't, projects like Better Strings Library would not be so appealing to use. Same with readline and other already made libraries. Knowing the general gist is great, handling the minutia yourself when there are already tools at your disposal rarely benefits people above getting experience to know when readline/bstrings/other library should be used instead of making own solution to solved problem.