0

I haven't really found any useful and simple information as to what "stdin" does and how it relates to fgets() when used for example like:

fgets(car[i].vehicle.brand, sizeof(car[i].vehicle.brand), stdin);
c0mp13x
  • 55
  • 1
  • 6
  • Do you know what `fgets` is expecting as the last parameter? – Eugene Sh. Apr 21 '20 at 21:13
  • @EugeneSh. As I have understood, it takes a parameter a FILE pointer to which it can write to. – c0mp13x Apr 21 '20 at 21:15
  • No, it is pointer to the stream to *read* from. So `stdin` is the handle of the **st**andar**d** **in**put stream. Which is your console unless redirected in the shell. – Eugene Sh. Apr 21 '20 at 21:17
  • 2
    @EugeneSh. So it is like an imaginary file where the user just "streams" data into it but without saving it somewhere permanently. – c0mp13x Apr 21 '20 at 21:21
  • Some functions such as `getchar()` gets its input from `stdin` which is automatically opened already for you. But there isn't a version of `fgets()` which gets its input from `stdin` so you have to specify it. `stdin` is already open. – Weather Vane Apr 21 '20 at 21:21
  • Relevant: [What is stdin in C language?](https://stackoverflow.com/questions/37719915/what-is-stdin-in-c-language) – Weather Vane Apr 21 '20 at 21:23
  • @WeatherVane Alright sure do! Thank you for your help! ^^ – c0mp13x Apr 21 '20 at 22:55

0 Answers0