|
由于刚学习gcc编程,碰到一大堆问题,还请各位不吝指教(有点烦喔).
源程序如下:
////////////////////////////////////////////////
//compute.c:简单计算器
////////////////////////////////////////////////
#include<stdio.h>
double sum(double a,double b);
double subtract(double a,double b);
double multiply(double a,double b);
double divide(double a,double b);
double remainder(double a,double b);
int main(void)
{
int choice;
double a,b;
double (*func)();
while(1)
{
printf("\n*****************************************");//输入提示询息
printf("\n1.sum");
printf("\n2.subtract");
printf("\n3.multiply");
printf("\n4.divide");
printf("\n5.remainder");
printf("\nInput a choice(any other key to exit):");
choice=getchar();
switch(choice)
{
case '1':
func=sum;
break;
case '2':
func=subtract;
break;
case '3':
func=multiply;
break;
case '4':
func=divide;
break;
case '5':
func=remainder;
default:
return;
}
printf("\n\nPlease input a:");
scanf("%lf",&a);
printf("Pleast input b;
scanf("%lf",&b);
printf("\nThe result is:%lf.\n",(*func)(a,b));
}
return 1;
}
double sum(double a,double b)
{
return a+b;
}
double subtract(double a,double b)
{
return a-b;
}
double multiply(double a,double b)
{
return a*b;
}
double divide(doublea,double b)
{
return a/b;
}
double remainder(double a,double b)
{
return (int)a%(int)b;
}
运行gcc -o compute.o compute.c后,出来下面错误信息:
compute.c:47:10: warning: multi-line string literals are deprecated
compute.c:48:13: warning: multi-line string literals are deprecated
compute.c: In function `main':
compute.c:47: `lf' undeclared (first use in this function)
compute.c:47: (Each undeclared identifier is reported only once
compute.c:47: for each function it appears in.)
compute.c:47: parse error before string constant
compute.c:47: stray '\' in program
compute.c:47: stray '\' in program
compute.c:49:33: warning: multi-line string literals are deprecated
compute.c:49:33: missing terminating " character
compute.c:47:10: possible start of unterminated string literal
请问怎么回事?
附带问题:
1.在gcc中,main的返回值是否只能为int型?
2.有没有像Turob C,最好像VC一样便洁的调试工具?gdb?
3.getche,getchar是在stdio.h中吗?(好久没用c了,有点忘了) |
|