一、goto语句
goto语句也称为无条件转移语句,其一般格式如:
goto 语句标号;
其中语句标号是按标识符规定书写的符号, 放在某一语句行的前面,标号后加半角冒号“:”。语句标号起标识语句的作用,与 goto 语句配合使用。
int main()
{
printf("哈哈哈\n");
goto again;
printf("嘿嘿嘿\n");
again:
printf("呵呵呵\n");
return 0;
}
打印结果:
关机程序:
#include <stdio.h>
#include <string.h>
int main()
{
char input[20] = { 0 };
system("shutdown -s -t 60");
again:
printf("请注意,你的计算机将在1分钟后关机,如取消关机,请输入:ESC\n请输入: ");
scanf("%s", input);
if (strcmp(input, "ESC") == 0)//比较两个字符串-strcmp()
{
system("shutdown -a");
}
else
{
goto again;
}
return 0;
}
打印结果:
二、函数概念
C语言函数是一种函数,用来编译C语言,一般包括字符库函数,数学函数,目录函数,进程函数,诊断函数,操作函数等。