It is necessary that the program in the loop requested to enter a value until q is entered. When q is entered, the program should close.

#include <windows.h> #include <conio.h> int _tmain() { int ch = 0; while (ch != 'q') { ch = _getch(); ch = toupper(ch); } } 

Where is the mistake?

  • Quotes must be single. - Oleksii Shapovalov
  • @ Alexey Shapovalov, ok still does not work - ololo
  • Where is the mistake? - Nicolas Chabanovsky
  • What do you want to do? And what exactly does not work? - ProkletyiPirat

2 answers 2

  char str=0;//тут должна быть хоть какаята инициализация, //иначе может ругаться на то что: "while (str != 'q')" str-неизвестен while (str != 'q'){//тут должны быть одинарные кавычки, //или может ругаться на const char str=getchar(); } 

But why bother? cin >> str; Is it easier? (sort of like a C ++ tag, why the heck would C?)

Added 12/11/2012

since the author redid his question, now the correct answer is for @Rules

    I don't even know C / C ++, but I suspect that toupper(ch) returns uppercase ch , and even if the user enters 'q' , do you really think that 'Q' == 'q' .

    • Yes, in this case, the main error is toupper () instead of tolower (). - avp 2:01
    • @rules, thanks for the compliment. I'm learning. Two years on the Delphi kodil now I retrain - ololo
    • Sorry, @olo but it seems to me that such errors are an elementary translation of the name of the function into Russian :) - Rules