?#include? <stdio.h>
void main(void)
{
char cValue='a';
int iValue=1234567;
long 1Value=7890123;
float fValue=3.141592;
double dValue=3.141592;
char*string="korea";
char buffer[100];
sprintf(buffer,"char type is %c", cValue);
puts(buffer);
sprintf(buffer,"int type is %d", iValue);
puts(buffer);
sprintf(buffer,"long type is %1d", 1Value);
puts(buffer);
sprintf(buffer,"float type is %f", fValue);
puts(buffer);
sprintf(buffer,"double type is %e", dValue);
puts(buffer);
sprintf(buffer,"char* type is %s", string);
puts(buffer);
}
Run Code Online (Sandbox Code Playgroud)
当我使用此代码编译时,出现语法和其他错误.
这段代码有什么问题?
错误消息:
76\76.c(7) : error C2059: syntax error : 'bad suffix on number'
76\76.c(7) : error C2143: syntax error : missing ';' before 'constant'
76\76.c(7) : warning C4091: ' ' : ignored on left of 'long ' when no variable is declared
76\76.c(7) : error C2146: syntax error : missing ';' before identifier 'Value'
76\76.c(7) : error C2065: 'Value' : undeclared identifier
76\76.c(8) : error C2143: syntax error : missing ';' before 'type'
76\76.c(9) : error C2143: syntax error : missing ';' before 'type'
76\76.c(10) : error C2143: syntax error : missing ';' before 'type'
76\76.c(11) : error C2143: syntax error : missing ';' before 'type'
76\76.c(13) : error C2065: 'buffer' : undeclared identifier
76\76.c(13) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
76\76.c(13) : warning C4024: 'sprintf' : different types for formal and actual parameter 1
76\76.c(14) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
76\76.c(14) : warning C4024: 'puts' : different types for formal and actual parameter 1
76\76.c(16) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
76\76.c(16) : warning C4024: 'sprintf' : different types for formal and actual parameter 1
76\76.c(17) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
76\76.c(17) : warning C4024: 'puts' : different types for formal and actual parameter 1
76\76.c(19) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
76\76.c(19) : warning C4024: 'sprintf' : different types for formal and actual parameter 1
76\76.c(19) : error C2059: syntax error : 'bad suffix on number'
76\76.c(19) : error C2146: syntax error : missing ')' before identifier 'Value'
76\76.c(19) : error C2059: syntax error : ')'
76\76.c(20) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
76\76.c(20) : warning C4024: 'puts' : different types for formal and actual parameter 1
76\76.c(22) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
76\76.c(22) : warning C4024: 'sprintf' : different types for formal and actual parameter 1
76\76.c(22) : error C2065: 'fValue' : undeclared identifier
76\76.c(23) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
76\76.c(23) : warning C4024: 'puts' : different types for formal and actual parameter 1
76\76.c(25) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
76\76.c(25) : warning C4024: 'sprintf' : different types for formal and actual parameter 1
76\76.c(25) : error C2065: 'dValue' : undeclared identifier
76\76.c(26) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
76\76.c(26) : warning C4024: 'puts' : different types for formal and actual parameter 1
76\76.c(28) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
76\76.c(28) : warning C4024: 'sprintf' : different types for formal and actual parameter 1
76\76.c(28) : error C2065: 'string' : undeclared identifier
76\76.c(29) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
76\76.c(29) : warning C4024: 'puts' : different types for formal and actual parameter 1
Run Code Online (Sandbox Code Playgroud)
long 1Value=7890123;
Run Code Online (Sandbox Code Playgroud)
您不能将数字用作变量名的第一个字符.
| 归档时间: |
|
| 查看次数: |
852 次 |
| 最近记录: |