Home > Back-end >  The problem of input bosses ask cycle
The problem of input bosses ask cycle

Time:10-11

Such as ruby roth want to do a simple ATM program, but the scanf can only enter two, three and will not be able to enter after the first how to solve?

CodePudding user response:

Add \ n

CodePudding user response:

Scanf_s have asked about parameters, scanf_s still have difference with the scanf,

Is updated version, after all, compared with scanf_s security, because scanf_s () is aimed at "the scanf () do not check the border, while reading the string may cause memory leakage

Lou ", scanf_s () is used to read the string, you must provide a number to indicate how many characters, most read in order to prevent overflow,

CodePudding user response:

refer to the second floor CHXCHXKKK response:
scanf_s have asked about parameters, scanf_s or is there a difference with the scanf,

Is updated version, after all, compared with scanf_s security, because scanf_s () is aimed at "the scanf () do not check the border, while reading the string may cause memory leakage

Lou ", scanf_s () is used to read the string, you must provide a number to indicate how many characters, most read in order to prevent overflow,

Combined with digital after no change

CodePudding user response:

Scanf_s for strings and character to differ
The key is you
Scanf_s (" % d ", & amp; Z);
Z is char types, you specify the integer input, is wrong
Scanf_s (" % c ", & amp; Z, 1);

In addition, digital and mixed characters from the keyboard, also note return characters in the buffer yet
Before reading the characters, add a fflush (stdin); To empty the keyboard buffer, then read character

Pay attention to the use of good the scanf and scanf_s return values, don't know what's the meaning of baidu to see their function specification,
The return value will tell you get back from the keyboard a few real effective value
  • Related