我偶然发现了这段代码,我想了解什么是 args[0][0]-'!'
的意思?我不明白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]'是args数组中第一个字符串的第一个字符,所以它将减去'!'的ascii代码从它 – bruceg
这是减去,正是它看起来像 - 你的问题是什么ASCII? –
第一个参数'argv [0]'通常是可执行文件名本身。但AFAIK'exec **'函数不会传递任何程序参数,所以这可能就是这种用法。 –