이 코드 블록을 우연히 만났는데 무엇을 이해하고 싶습니다. 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 배열의 첫 번째 문자열의 첫 번째 문자이므로 '!'에 대한 아스키 코드를 뺍니다. 그것으로부터 – bruceg
그것은 닮았을 것입니다 - ASCII가 무엇인지에 대한 질문입니까? –
첫 번째 인수'argv [0]'은 일반적으로 실행 파일 이름 자체입니다. 그러나 AFAIK'exec **'함수는 어떤 프로그램 인수도 전달하지 않으므로 이러한 사용법이 될 수 있습니다. –