的Visual Studio 2012"语法错误" [英] Visual Studio 2012 "Syntax Error"
问题描述
我收到以下错误,当我试图编译我的项目在Visual Studio 2012:
1 GT; ------启动生成:项目:ConsoleApplication1,配置:调试的Win32 ------
1> main.c中
1> E:\\ main.c中(28):警告C4996:'scanf函数':此函数或变量可能是不安全的。考虑使用,而不是scanf_s。要禁用德precation,使用_CRT_SECURE_NO_WARNINGS。详细信息请参见在线帮助。
1> C:\\ Program Files文件(x86)的\\微软的Visual Studio 11.0 \\ VC \\ \\包括stdio.h中(290):参见scanf函数'的声明
1> E:\\ main.c中(30):错误C2143:语法错误:缺少;前型
1> E:\\ main.c中(31):错误C2143:语法错误:缺少;前型
1> E:\\ main.c中(33):错误C2065:answerMin:未声明的标识符
1> E:\\ main.c中(33):错误C2065:answerMax:未声明的标识符
1> E:\\ main.c中(35):错误C2065:answerMax:未声明的标识符
1> E:\\ main.c中(36):错误C2065:answerMin:未声明的标识符
==========生成:0成功,1失败,0了最新,0已跳过==========
下面是code main.c中
的#include<&stdlib.h中GT;
#包括LT&;&stdio.h中GT;双A;
双B:
双ComputeMaximum(双,双);
双ComputeMinimum(双,双);INT主要(无效)
{ 的printf(\\ n请输入比较\\ n两个数值); scanf函数(%D,&安培;一,和b); 双answerMax = ComputeMaximum(A,B);
双answerMin = ComputeMinimum(A,B); 的printf(%d个和%d个最小为%d,最大为%d \\ n,A,B,answerMin,answerMax); 的printf(%D,answerMax);
的printf(%D,answerMin); 系统(暂停);
返回0;}
下面是code为ComputeMinimum.c
双ComputeMinimum(双一,双二)
{
double结果= 0;
(A> B)? (B =结果):(α=导致);
返回结果;}
下面是code为ComputeMaximum.c
双ComputeMaximum(双一,双二)
{
double结果= 0;
(A> B)? (A =结果):(B =结果);
返回结果;}
scanf函数(%D,&安培;一,和b);
必须
scanf函数(%LF%LF,&安培;一,和b);
由于 A
和 B
双打(与值之间有一个空格)。
同为
的printf(%d个和%d个最小为%d,最大为%d \\ n,A,B,answerMin,answerMax);
变更%d个
到%F
还要注意的是在
双ComputeMinimum(双一,双二)
{
double结果= 0;
(A> B)? (B =结果):(α=导致);
返回结果;}
结果
始终为0,更改为
(A> B)? (结果= b)的:(结果=一);
同为 computeMaximum
当然,你需要包括含的main.c
这些函数的头(编译器警告这个事实)
I'm getting the following errors when I attempt to compile my project in Visual Studio 2012:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1> main.c
1>e:\main.c(28): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\stdio.h(290) : see declaration of 'scanf'
1>e:\main.c(30): error C2143: syntax error : missing ';' before 'type'
1>e:\main.c(31): error C2143: syntax error : missing ';' before 'type'
1>e:\main.c(33): error C2065: 'answerMin' : undeclared identifier
1>e:\main.c(33): error C2065: 'answerMax' : undeclared identifier
1>e:\main.c(35): error C2065: 'answerMax' : undeclared identifier
1>e:\main.c(36): error C2065: 'answerMin' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here is the code in main.c
#include <stdlib.h>
#include <stdio.h>
double a ;
double b ;
double ComputeMaximum( double, double ) ;
double ComputeMinimum( double, double ) ;
int main(void)
{
printf("\nPlease enter two numeric values for comparison\n") ;
scanf("%d%d", &a, &b );
double answerMax = ComputeMaximum( a, b ) ;
double answerMin = ComputeMinimum( a, b ) ;
printf("Of %d and %d the minimum is %d and the maximum is %d\n", a, b, answerMin, answerMax ) ;
printf("%d", answerMax ) ;
printf("%d", answerMin ) ;
system("pause");
return 0;
}
Here is the code for ComputeMinimum.c
double ComputeMinimum( double a, double b )
{
double result = 0 ;
( a > b ) ? ( b = result ) : ( a = result ) ;
return result ;
}
Here is the code for ComputeMaximum.c
double ComputeMaximum(double a, double b)
{
double result = 0 ;
( a > b ) ? ( a = result ) : ( b = result ) ;
return result ;
}
scanf("%d%d", &a, &b );
must be
scanf("%lf %lf", &a, &b);
because a
and b
are doubles (with a space between values).
same for
printf("Of %d and %d the minimum is %d and the maximum is %d\n", a, b, answerMin, answerMax ) ;
change %d
to %f
Also note that in
double ComputeMinimum( double a, double b )
{
double result = 0 ;
( a > b ) ? ( b = result ) : ( a = result ) ;
return result ;
}
result
is always 0, change to
( a > b ) ? ( result = b ) : ( result = a ) ;
same for computeMaximum
And of course, you need to include the header containing those functions in main.c
(compiler is warning about this fact)
这篇关于的Visual Studio 2012&QUOT;语法错误&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!