gets command in c

Posted 04 January 2013 - 10:01 PM

hello, i want to ask about the "gets" command (which has the same function as scanf). i use the ubuntu 11.10 and has no problem in the program with the "gets"...

but, when i try it in another pc with ubuntu 10.10 (if i'm not wrong, it has a different environment with ubuntu 11.10).
my question is: is that true? i mean, is that true that the gets command doesn't work in ubuntu 10.10? and is there any subtitution? and is there any advice?

Re: gets command in c

Posted 04 January 2013 - 11:15 PM

With scanf(), you can read in multiple words, but you have to specify that with the string formatter- one per word. You can also use getc() and pass it stdin. The idea with getc() is that you malloc() a buffer, and you would realloc() a bigger buffer when it fills up. Repeat this until you've read in the string in its entirety.