为了账号安全,请及时绑定邮箱和手机立即绑定

是一名c语言初学者,在试用goto语句出现问题,求帮帮忙!

是一名c语言初学者,在试用goto语句出现问题,求帮帮忙!

C PHP
人到中年有点甜 2022-03-24 15:15:03
#include<stdio.h>int main(){goto state;state ;printf("let's play a game");char c;c =getchar();fflush(stdin);}--------------------配置: mingw5 - CUI Debug, 编译器类型: MinGW--------------------检查文件依赖性...正在编译 C:\Users\hust\Documents\C-Free\Temp\未命名1.cpp...[Error] C:\Users\hust\Documents\C-Free\Temp\未命名1.cpp:5: error: `state' was not declared in this scope[Error] C:\Users\hust\Documents\C-Free\Temp\未命名1.cpp:4: error: label `state' used but not defined[Warning] C:\Users\hust\Documents\C-Free\Temp\未命名1.cpp:11:2: warning: no newline at end of file构建中止 未命名1: 2 个错误, 1 个警告
查看完整描述

3 回答

?
至尊宝的传说

TA贡献1789条经验 获得超10个赞

标签要使用冒号,而不是分号,

1state:  // <-- 这里是冒号

另外,goto语句会破坏程序结构性,尽量避免使用。


查看完整回答
反对 回复 2022-03-28
?
ibeautiful

TA贡献1993条经验 获得超5个赞

#include<stdio.h>
int main()
{
goto state;
state ://用冒号
printf("let's play a game");
char c;
c =getchar();
fflush(stdin);

}
//goto尽量不要用



查看完整回答
反对 回复 2022-03-28
?
慕侠2389804

TA贡献1719条经验 获得超6个赞

在软件设计的过程中有一天就是尽量不用goto语句,有极大的不可控性,所以建议趁早放弃它,养成好习惯用for 和while循环简练易懂,你的state没有定义

查看完整回答
反对 回复 2022-03-28
  • 3 回答
  • 0 关注
  • 183 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号