Proper way to input a dynamically-allocated string



I know it must sound like a newbie question, but I never really had to
bother with that before, and I didn't even find an answer in the c.l.c
FAQ

I'd like to know what's the really proper way for input a string in an
array of char that's dynamically allocated. I mean, I wish not to see
any such things as char mystring[100]; I don't want to see any number
(if possible) I just want to declare something like char *mystring; and
then I don't know how allocate it with just as many chars (with the
space for the \0 of course) as you get from stdin.

I'd really like to know once for all what's the smartest way of
inputing strings from stdin and storing them in a way so they take just
the needed space and I don't want to see any number such as 100 or
10,000 or even 4,294,967,296 in my code. Any way it can be done?

.



Relevant Pages

  • Re: Proper way to input a dynamically-allocated string
    ... I'd like to know what's the really proper way for input a string ... in an array of char that's dynamically allocated. ... inputing strings from stdin and storing them in a way so they ... take just the needed space and I don't want to see any number ...
    (comp.lang.c)
  • Re: Curses???
    ... Do I use ioctl() to set the c_lflag. ... have it open (STDIN) and the following code may be more useful to work ... int inhibitStdinInBuffering(void) ... ioctl(STDIN, TCGETA, (char *)&originalIoSettings); ...
    (comp.os.lynx)
  • Re: Curses???
    ... Do I use ioctl() to set the c_lflag. ... have it open (STDIN) and the following code may be more useful to work ... int inhibitStdinInBuffering(void) ... ioctl(STDIN, TCGETA, (char *)&originalIoSettings); ...
    (comp.os.lynx)
  • Re: alloca
    ... ptr = fgets, SIZE, stdin); ... {char buffer; ... If the implementation uses a stack for allocaand for local variables, then it seems stack overflow is equally likely. ...
    (comp.lang.c)
  • Re: PostMessage() Error
    ... PostMessage(hwnd, WM_CHAR, (unsigned char) *pc, 1L); ... PostMessageafter processing 4k of stdin piped data (I have 14K of ... Also, tried WaitForInputIdleto slow down PostMessage() after 1000 characters, it doesn't help. ...
    (microsoft.public.vc.language)