-8

Why C standards contain many unsafe functions, which are useless (in good programs them don't use) and harmful, for example getchar? Why C standard doesn't contain instead of them the useful functions, for example getch, and getche? It is only one of many examples...

UPD I confused: gets instead of getchar.

Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182

3 Answers3

10

Do you mean gets? To not break old programs. The road to obsoleteness is long. And besides, it has been deprecated.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • But why not added the `getch`, and `getche`? To whom do they hinder? Why to pull for itself a sore tail? Why not to cut off it? – Andrey Bushman Dec 23 '12 at 16:51
  • 6
    @Bush: There are many good reasons not to add them. One is that many historical systems have functions by the same names which do completely different things; attempting to standardize one of those would be unacceptable to everybody else. Another reason is that these functions operate at a completely different level from stdio. The curses `getch` function, for example, works with curses key codes, not characters, and is not compatible with stdio buffering. – R.. GitHub STOP HELPING ICE Dec 23 '12 at 16:54
  • >Do you mean gets? @Carl Norum Yes, I am sorry, I confused with `gets`. – Andrey Bushman Dec 23 '12 at 17:02
2

gets is deprecated in C99 and has been removed in C11.

C11(ISO/IEC 9899:201x) Forward/6

removed the gets function ()

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
1

You can't implement getch() [reading without buffering] on a teletype (terminal that looks like a typewriter). Or any type of terminal where the data is stored in the terminal until you hit enter.

There are functions that do this sort of things, but remember that C is a language that is supposed to "run on anything".

gets was part of the standard library many years ago, so it has to stay - otherwise, old code won't compile, and a lot of people like to use old code (because it's a lot of work to fix up 1000000 lines of messy code that used to work!)

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227