strinput1 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. GETS(3) Linux Programmer's Manual GETS(3)
  2. NAME
  3. fgetc, fgets, getc, getchar, gets, ungetc - input of characters and
  4. strings
  5. SYNOPSIS
  6. #include <stdio.h>
  7. int fgetc(FILE *stream);
  8. char *fgets(char *s, int size, FILE *stream);
  9. int getc(FILE *stream);
  10. int getchar(void);
  11. char *gets(char *s);
  12. int ungetc(int c, FILE *stream);
  13. DESCRIPTION
  14. fgetc() reads the next character from stream and returns it as an
  15. unsigned char cast to an int, or EOF on end of file or error.
  16. getc() is equivalent to fgetc() except that it may be implemented as a
  17. macro which evaluates stream more than once.
  18. getchar() is equivalent to getc(stdin).
  19. gets() reads a line from stdin into the buffer pointed to by s until
  20. either a terminating newline or EOF, which it replaces with a null byte
  21. ('\0'). No check for buffer overrun is performed (see BUGS below).
  22. fgets() reads in at most one less than size characters from stream and
  23. stores them into the buffer pointed to by s. Reading stops after an
  24. EOF or a newline. If a newline is read, it is stored into the buffer.
  25. A terminating null byte ('\0') is stored after the last character in
  26. the buffer.
  27. ungetc() pushes c back to stream, cast to unsigned char, where it is
  28. available for subsequent read operations. Pushed-back characters will
  29. be returned in reverse order; only one pushback is guaranteed.
  30. Calls to the functions described here can be mixed with each other and
  31. with calls to other input functions from the stdio library for the same
  32. input stream.
  33. For nonlocking counterparts, see unlocked_stdio(3).
  34. RETURN VALUE
  35. fgetc(), getc() and getchar() return the character read as an unsigned
  36. char cast to an int or EOF on end of file or error.
  37. gets() and fgets() return s on success, and NULL on error or when end
  38. of file occurs while no characters have been read.
  39. ungetc() returns c on success, or EOF on error.
  40. CONFORMING TO
  41. C89, C99, POSIX.1-2001. LSB deprecates gets(). POSIX.1-2008 marks
  42. gets() obsolescent.
  43. BUGS
  44. Never use gets(). Because it is impossible to tell without knowing the
  45. data in advance how many characters gets() will read, and because
  46. gets() will continue to store characters past the end of the buffer, it
  47. is extremely dangerous to use. It has been used to break computer
  48. security. Use fgets() instead.
  49. It is not advisable to mix calls to input functions from the stdio
  50. library with low-level calls to read(2) for the file descriptor associ‐
  51. ated with the input stream; the results will be undefined and very
  52. probably not what you want.
  53. SEE ALSO
  54. read(2), write(2), ferror(3), fgetwc(3), fgetws(3), fopen(3), fread(3),
  55. fseek(3), getline(3), getwchar(3), puts(3), scanf(3), ungetwc(3),
  56. unlocked_stdio(3)
  57. COLOPHON
  58. This page is part of release 3.35 of the Linux man-pages project. A
  59. description of the project, and information about reporting bugs, can
  60. be found at http://man7.org/linux/man-pages/.
  61. GNU 2011-09-28 GETS(3)