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

#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 个警告

人到中年有点甜
浏览 184回答 3
3回答

至尊宝的传说

标签要使用冒号,而不是分号,1state:&nbsp;&nbsp;//&nbsp;<--&nbsp;这里是冒号另外,goto语句会破坏程序结构性,尽量避免使用。

ibeautiful

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

慕侠2389804

在软件设计的过程中有一天就是尽量不用goto语句,有极大的不可控性,所以建议趁早放弃它,养成好习惯用for 和while循环简练易懂,你的state没有定义
打开App,查看更多内容
随时随地看视频慕课网APP