سؤال

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