Ich stolperte über diesen Block von Code und ich möchte verstehen, was args[0][0]-'!'
bedeutet?Ich verstehe nicht, was args [0] [0] - '!' bedeutet
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]);
}
}
Dieser Code ist von diesem github Konto: https://github.com/deepakavs/Unix-shell-and-history-feature-C/blob/master/shell2.c
'args [0] [0]' ist das erste Zeichen der ersten Zeichenfolge im args-Array, daher wird der ASCII-Code für '!' Subtrahiert. davon – bruceg
Es wird subtrahiert, genau wie es aussieht - ist deine Frage, was ASCII ist? –
Das erste Argument 'argv [0]' ist normalerweise der ausführbare Dateiname selbst. Aber AFAIK 'exec **' Funktionen übergeben kein Programmargument, also könnte dies eine solche Verwendung sein. –