문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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

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

removed the gets function ()

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!)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top