gpt4 book ai didi

c - 以下C代码编译错误的原因

转载 作者:行者123 更新时间:2023-11-30 21:32:40 25 4
gpt4 key购买 nike

‪#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);
}

当我用这段代码编译时,发生语法和其他错误。

这段代码有什么问题?

错误消息:

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

最佳答案

long 1Value=7890123;

不能使用数字作为变量名称的第一个字符。

关于c - 以下C代码编译错误的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20660842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com