0

I'm often using C code to take some input and manipulate it; for example, I want to scan a full phrase like "hello world" but as it contains a space, I find myself forced to use "gets" to include the spaces or even tabs sometimes.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Kami SM
  • 29
  • 6
  • 2
    [You cannot use `gets()` safely](https://stackoverflow.com/q/1694036/15168) — you should never, ever use it. That question highlights alternatives. Do you want to read lines, or do you have some other form of input in mind? – Jonathan Leffler Jan 26 '22 at 20:55
  • 2
    @Kami SM Instead use fgets. – Vlad from Moscow Jan 26 '22 at 20:56
  • 1
    You can use `sscanf` to parse the string after reading it in with `fgets`. Is that what you are after? – kaylum Jan 26 '22 at 21:12

1 Answers1

0

you cant use scanf() or fgets, just remember use the stdin as input stream

DolevA
  • 16
  • 1
  • 1
    Do you mean one *can* use those functions? In that case, a little more detail would be warranted, especially for `scanf()`. As far as `stdin` being an available stream, did you then mean that one can use *`fscanf()`*? – John Bollinger Jan 26 '22 at 21:28