What happens when you call scanw("%*d");
There is such code:

 while (!quit) { for(int i = 0; i < rate; i++){ ch = getch(); if (ch != ERR){ for (int j = 0; j < (rate-i); j++) getch(); break; } } //scanw("%*d"); 

When I call scanw, ch as far as I understand becomes equal to -1.
Well, I need to use it just want to understand what it does.

  • one
    Are you sure that scanw , not scanf ? ... - Harry
  • @Harry is ncurses, he does what scanf does. But still - no - I'm not sure. Although I just want to understand what he is doing. - CGLike
  • If it were scanf , it would read a decimal integer (skipping the preceding whitespace characters, if any), while reading, would stop at the first character that cannot be interpreted as part of the number, and just throw away what was read into nowhere ... - Harry
  • @Harry, w for window, see ncurses. - 0andriy
  • @Harry wscanw - for window - CGLike

1 answer 1

scanw not a standard C function.

The meaning of the format specification in this function call.

 scanw("%*d"); 

means that an integer will be read (the conversion character d in the format specification %*d ), but it will not be saved anywhere (the * flag before the conversion character d in the specification %*d format). That is, an integer in the input stream is skipped (retrieved, but not stored anywhere).

  • Thank. It seems that such a scanw would clear the stream for the next keystroke. And why does ch change then? - CGLike
  • @CGLike I did not understand the meaning of your question. ch is changed because it reads in a loop. - Vlad from Moscow
  • If after a cycle to use scanw ("% * d"); then ch becomes -1 anyway - CGLike
  • @CGLike scanw and getch are not standard features. You can search for their description on the Internet. I don’t think it makes a lot of sense to figure out what these functions and the code that you present do. - Vlad from Moscow