在每一句语句后面加上
if(getch() == 'x')exit(0)
例如:
#include<stdio.h>int main(void)
{
...
if(getch() == 'x')
exit(0)
...
if(getch() == 'x')
exit(0)
...
if(getch() == 'x')
exit(0)
...
if(getch() == 'x')
exit(0)
return 0
}
c语言退出整个程序或函数的命令是return、goto 、break 、break。
1、return 返回;
return 表示从被调用函数返回主调函数继续执行,返回时可附带一个返回值,由return后面的参数设定。
2、goto 无条件跳转;
goto语句也称作无条件转移语句,其一般格式为goto语句标号:其中语句标号是按照标识符规定书写的符号,放在某一行语句行的前面,标号后加冒号(:)。
3、break 调处最近一层块;
大多数情况下是终止上一层的循环,C语言中break在switch中执行一条case后跳出语句的作用 使程序跳出switch执行switch以后的语句 如果没有break switch会从满足条件的地方执行到switch结构结束。
扩展资料
break语句使用
示例:
#include <stdio.h>
void main()
{
int x=1
while(x<=4)
{
printf("x=%d\n",x)
if (x==3)
{
break
}
x++
}
}
#include<stdio.h>#include <stdlib.h>
void main()
{
int i=0
printf("1.执行1 *** 作\n2.执行2 *** 作\n3.退出\n")
printf("请输入你所需的 *** 作\n")
scanf("%d",&i)
switch(i)
{
case 1:printf("1 *** 作")break
case 2:printf("2 *** 作")break
case 3:system("exit")break
default:break
}
system("pause")
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)