c - 我不明白 args[0][0] -'!' 是什么意思

标签 c shell unix

我偶然发现了这段代码,我想了解什么 args[0][0]-'!' 是什么意思?

else if (args[0][0]-'!' ==0)
{   int x = args[0][1]- '0'; 
    int z = args[0][2]- '0'; 

    if(x>count) //second letter check
    {
    printf("\nNo Such Command in the history\n");
    strcpy(inputBuffer,"Wrong command");
    } 
    else if (z!=-48) //third letter check
    {
    printf("\nNo Such Command in the history. Enter <=!9 (buffer size        is 10 along with current command)\n");
    strcpy(inputBuffer,"Wrong command");
    }
    else
    {

        if(x==-15)//Checking for '!!',ascii value of '!' is 33.
        {    strcpy(inputBuffer,history[0]);  // this will be your 10 th(last) command
        }
        else if(x==0) //Checking for '!0'
        {    printf("Enter proper command");
            strcpy(inputBuffer,"Wrong command");
        }

        else if(x>=1) //Checking for '!n', n >=1
        {
            strcpy(inputBuffer,history[count-x]);

        }

    }

此代码来自此 github 帐户:https://github.com/deepakavs/Unix-shell-and-history-feature-C/blob/master/shell2.c

最佳答案

'!' 只是一个数值的文本表示,它以指定的编码对感叹号进行编码。 args[0][0] 是数组第一个元素的第一个字符。

那么当 x - y == 0 时?当 x == y 时,将 y 移到另一边,这样代码就等同于 args[0][0] == '!'.

不过,我看不出有任何实际理由将等价性表示为示例中的减法。

关于c - 我不明白 args[0][0] -'!' 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40008060/

相关文章:

c - 在 c 1 中使用 realloc

c - 二维数组 C 中的 bool 表

linux - 返工查找命令以使用其他扩展

PHP。获取用户主目录(用于虚拟主机)

javascript - 有人可以告诉我如何在 Unix 上运行 Node.js 吗?

linux - 我可以在哪里放置脚本来启动 init centos?

c - lex 和 yacc 之前的第二个输入中存在语法错误

shell - 将命令输出放入 shell 中以供进一步编辑

linux - WebDav 检测文件夹的写权限

c - atoi 和前导 0 用于十进制数