Hello!

scanf("%i", &reverse_sort); 

The compiler curses the incompatibility of the specifier and the input data:

/home/yura/gitclone/c_git/arr_sort.c|15| warning: format "% i"

  • one
    So _Bool ? - user6550
  • one
    stdbool.h, so bool variable_name. - gnuvse
  • Good question. Judging by the discussions on the Internet, in any way, scanf does not know how bool. But we will wait for the experts. - VladD
  • one
    Well, bool is a fashionable invention for Si. Previously, it simply was not. Inside it is a char (or unsigned char, shorter than 1 byte. Of an integer type). So, enter, for example, the values โ€‹โ€‹in the auxiliary int variable and assign. - avp
  • @avp, or just initially use int :-) If the situation allows, of course. - user6550

2 answers 2

One of the cases when different parts of the standard are tightened at different speeds. There is no specifier for bool variables yet. The correct way to do what you want is:

 int temp; bool reverse_sort; scanf("%i", &temp); reverse_sort = temp; 
  • Yes, and so it is possible. But it seems to me an extra variable, you can do as suggested by the author below. And it is better to use the good old char - gnuvse
  • And than char better? For me, on the contrary, with int fuss is less, and efficiency is more :) - user6550
  • @gnuvse: This is if _Bool not defined as an int in this implementation. Think about what will be with the value 257 . - VladD
  • @gnuvse I answered the question. If the question was: how to do it correctly, I would answer that you should use int instead of bool , as it has been done in C for the last 45 years. - Mark Shevchenko
  • one
    @Mark Shevchenko, you have an error here: %I is not the same as %i . In this case, %i should be used. - mega

There is no such format. Read int - and then bring it to bool .

  • This is if the value is written as 0/1, and not false / true. - VladD
  • And in stdbool.h they are clearly defined as 0 and 1. - user6550
  • Made, works, true type confusion. But I understand that any non-zero number when casting it leads to 1? - gnuvse
  • Type yes, but not to 1, but to true . But only while we are talking about values, and not about pointers, as is the case with scanf() . - user6550