问题描述:

#include <stdio.h>

#include <conio.h>

int main(void)

{

int num1;

int num2;

printf("Enter 2 numbers:\n");

scanf("%d", &num1);

scanf("%d", &num2);

if (num1 == num2){

printf("Equal");

}

getchar();

getchar();

}

The tutorial has this: #include <conio.h>

i tried it without #include <conio.h> and works ok...

But why did he put it? here is this tutorial.

网友答案:

Because in the tutorial it is getch() not getchar().

getch() is declared in conio.h, whereas getchar() is declared in stdio.h.

网友答案:

conio.h is a non-standard header that was shipped with many old C compilers for MS-DOS. It is not necessary in the code you posted, as none of that code requires its definitions. If including it produces an error, that is because conio.h is not available on your system. You may want to consult a more up-to-date tutorial if the one you're using is referencing DOS-specific headers.

Edit: Ouch, just looked at the linked tutorial. 2009? Someone is including conio.h as boilerplate C code in a tutorial from 2009? What a cruel world this is.

网友答案:

All the functions you are using are defined in stdio.h, it doesn't seem to use anything that is inside conio.h, thus rendering it useless in this case.

网友答案:

It works because all the functions used in the code - scanf, printf, getchar - are declared in stdio.h.

相关阅读:
Top