用goto语句写一个程序控制电脑的开关机及取消开关机

goto语句:

C语言中提供了随意滥用的goto语句和标记跳转的符号

最常见的用法终止程序在某些深度嵌套的结构的处理过程,例如一次跳出两层或者多层循环

需要运用到system函数和strcmp函数

system, _wsystem

Execute a command.

int system( const char *command );

int _wsystem( const wchar_t *command );

RoutineRequired HeaderCompatibility
system<process.h> or <stdlib.h>ANSI, Win 95, Win NT
_wsystem<process.h> or <stdlib.h> or <wchar.h>Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIBSingle thread static library, retail version
LIBCMT.LIBMultithread static library, retail version
MSVCRT.LIBImport library for MSVCRT.DLL, retail version

Return Value

If command is NULL and the command interpreter is found, the function returns a nonzero value. If the command interpreter is not found, it returns 0 and sets errno to ENOENT. If command is not NULL, system returns the value that is returned by the command interpreter. It returns the value 0 only if the command interpreter returns the value 0. A return value of – 1 indicates an error, and errno is set to one of the following values:

shutdown -s -t -60

-s设置关机   -t设置时间关机  60 60秒之后关机

shutdown -a

-a设置取消关机

system()执行系统命令

strcmp, wcscmp, _mbscmp

Compare strings.

int strcmp( const char *string1, const char *string2 );

int wcscmp( const wchar_t *string1, const wchar_t *string2 );

int _mbscmp(const unsigned char *string1, const unsigned char *string2 );

RoutineRequired HeaderCompatibility
strcmp<string.h>ANSI, Win 95, Win NT
wcscmp<string.h> or <wchar.h>ANSI, Win 95, Win NT
_mbscmp<mbstring.h>Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIBSingle thread static library, retail version
LIBCMT.LIBMultithread static library, retail version
MSVCRT.LIBImport library for MSVCRT.DLL, retail version

Return Value

The return value for each of these functions indicates the lexicographic relation of string1 to string2.

ValueRelationship of string1 to string2
< 0string1 less than string2
0string1 identical to string2
> 0string1 greater than string2

On an error, _mbscmp returns _NLSCMPERROR, which is defined in STRING.H and MBSTRING.H.

Parameters

string1, string2

Null-terminated strings to compare

Remarks

The strcmp function compares string1 and string2 lexicographically and returns a value indicating their relationship. wcscmp and _mbscmp are wide-character and multibyte-character versions of strcmp. The arguments and return value of wcscmp are wide-character strings; those of _mbscmp are multibyte-character strings. _mbscmp recognizes multibyte-character sequences according to the current multibyte code page and returns _NLSCMPERROR on an error. (For more information, see Code Pages.) These three functions behave identically otherwise.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined_MBCS Defined_UNICODE Defined
_tcscmpstrcmp_mbscmpwcscmp

The strcmp functions differ from the strcoll functions in that strcmp comparisons are not affected by locale, whereas the manner of strcoll comparisons is determined by the LC_COLLATE category of the current locale. For more information on the LC_COLLATE category, see setlocale.

In the “C” locale, the order of characters in the character set (ASCII character set) is the same as the lexicographic character order. However, in other locales, the order of characters in the character set may differ from the lexicographic order. For example, in certain European locales, the character 'a' (value 0x61) precedes the character 'ä' (value 0xE4) in the character set, but the character 'ä' precedes the character 'a' lexicographically.

In locales for which the character set and the lexicographic character order differ, use strcoll rather than strcmp for lexicographic comparison of strings according to the LC_COLLATE category setting of the current locale. Thus, to perform a lexicographic comparison of the locale in the above example, use strcoll rather than strcmp. Alternatively, you can use strxfrm on the original strings, then use strcmp on the resulting strings.

_stricmp, _wcsicmp, and _mbsicmp compare strings by first converting them to their lowercase forms.Two strings containing characters located between 'Z' and 'a' in the ASCII table ('[', '\', ']', '^', '_', and '`') compare differently, depending on their case. For example, the two strings "ABCDE" and "ABCD^" compare one way if the comparison is lowercase ("abcde" > "abcd^") and the other way ("ABCDE" < "ABCD^") if the comparison is uppercase.

//写一个程序控制电脑的开关机及取消开关机
//需要运用到system函数和strcmp函数
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main()
{
    char input[20]={0};
    system("shutdown -s -t 60");
    flag:
    printf("请注意:\n你的设备将在一分钟之后关机,请输入Treasure取消关机\n");
    scanf("%s",input);
    if (strcmp(input,"Treasure")==0)
    {
        system("shutdown -a");
    }
    else
    {
        goto flag;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值