When copying the code it gives an error using the WHILE function in C

0
#include <stdio.h>
#include <string.h>
int main()
{
    int num_key=666;
    do
    {
        puts("\n\n\t*********************************************");
        puts("\t*                                           *");
        puts("\t*     Calculador de temperatura             *");
        puts("\t*                                           *");
        puts("\t*                                           *");
        puts("\t*                                           *");
        puts("\t*          DIGITE SUA SENHA                 *");
        puts("\t*                                           *");
        puts("\t*                                           *");
        puts("\t*                                           *");
        puts("\t*  DIGITE 0 PARA SAIR                       *");
        puts("\t*********************************************");
        scanf("%i",num_key);                    
    }while(num_key!=123);
}

I have a problem in this while loop, I can not find the problem, it all comes up that I run it from the error and it closes. I checked and re-written the logic 2 times.

    
asked by anonymous 01.04.2017 / 18:05

1 answer

4

An important tip is to enable all warnings displayed by the compiler.

See the warnings for your program:

Seethefirstwarning,heissayingthatheexpectsaint*insteadofaint,ashisnum_keyvariableisnotapointer,soheneedstouse&topasstheaddresstoinsteadofthevalueforthefunctionscanf(),sothecompilerstopsgivingwarnings.

Thesecondwarningreferstothereturnofyourmainfunction.Thisfunctionofyoursisreturninganinteger,soitisnecessarytoassignthe

return0;

or

return1;

Incaseanerroroccursinyourprogram,noticethatthecompileralsoalertsyouaboutthis.

Yourcode:

#include<stdio.h>#include<string.h>intmain(void){intnum_key=666;do{puts("\n\n\t*********************************************");
        puts("\t*                                           *");
        puts("\t*     Calculador de temperatura             *");
        puts("\t*                                           *");
        puts("\t*                                           *");
        puts("\t*                                           *");
        puts("\t*          DIGITE SUA SENHA                 *");
        puts("\t*                                           *");
        puts("\t*                                           *");
        puts("\t*                                           *");
        puts("\t*  DIGITE 0 PARA SAIR                       *");
        puts("\t*********************************************");
        scanf("%i", &num_key);
    }while(num_key!=123);

    return 0;
}
    
01.04.2017 / 18:26