我从.h文件中调用scanf函数时遇到了麻烦。
mylib.h
intnums() //Entering 2 numbers
{
textcolor(WHITE);
printf("\nIntroduza dois números para realizar a operação selecionada.\n");
scanf("%i%i",&a,&b);
}
sumsub.h
sum(int a, int b) //Operation using previous introduction
{
textcolor(WHITE);
printf("\nA soma é: %i\n",a+b);
}
main.c中
case 1:
linha();
intnums();
sum(int b, int c);
delay4sec();
clear();
break;
//intnums calls for the function of entering the numbers and sum uses the entered numbers in intnums to calculate.
我是编码的新手,我仍然不太了解它,因此我想请求帮助来解决这个问题。提前谢谢。
答案 0 :(得分:-1)
您必须使用extern
关键字在文件之间共享变量
mylib.h
#include<stdio.h>
extern a,b;
intnums() //Entering 2 numbers
{
textcolor(WHITE);
printf("\nIntroduza dois números para realizar a operação selecionada.\n");
scanf("%i%i",&a,&b);
}
sumsub.h
sum(int a, int b) //Operation using previous introduction
{
textcolor(WHITE);
printf("\nA soma é: %i\n",a+b);
}
main.c中
case 1:
linha();
intnums();
sum(a,b);// you don,t have to use data type to pass the variable a&b are extern which are read by mylib.h
delay4sec();
clear();
break;