/safeinputc

safeinputc

Primary LanguageC

safeinputc

'Safe' stdin input in C

  • fgets truncates the input to avoid overflows
  • buffer cleaned only if strlen(string) == sizeof(string) so that no newlines need to be entered twice
  • last element of the array reserved for the nul terminator
  • changes newline created by fgets to nul