What is the return value of strcmp in c.I wrote the following code in c.
Code:
char parse(char buffer[],int i)
{
buffer[i] = '\0';
argument[0] = strtok(buffer, " ");
numberOfArguments = 1;
argument[numberOfArguments] = strtok(NULL, " ");
while (argument[numberOfArguments] != NULL) {
numberOfArguments++;
argument[numberOfArguments] = strtok(NULL, " ");
}
return numberOfArguments;
}
changeDirectory(char buffer[],int i){
parse(buffer,i);
int l=0;
while(l<numberOfArguments+1){
printf("argument [%d] is %s\n",l,argument[l]);
l++;
}
int main(){
char *s;
while(1)
{
printf("myshell>> ");
int i = 0;
while ((i < MAX) && ((buffer[i] = getchar()) != '\n') && buffer[i] != EOF)
i++;
if (i == MAX) {
buffer[MAX-1] = '\0';
while (getchar() != '\n');
printf("argument too long\n");
}
if (!strcmp(argument[0], "cd"))
changeDirectory(buffer,i);
the out put is always Null after argument[0].That means some how it is loosing the input after "cd".Why is that does strcmp turn the other valus after cd to null???