Hi im making a shell program that reads a line of input from the user, then if "cont" is detected as the first word of the line inputted, the line will be tokenized.
here's my main code
Code:
main ()
{
char line [ MAXLINE ], * words [ MAXWORDS ], message [ MAXLINE ];
int stop =0 , nwords =0;
while (1)
{
printf (" Enter line: " );
if ( NULL == fgets ( line , MAXLINE , stdin ))
return 0;
tokenize ( line , words ,& nwords );
}
}
here is my tokenize code:
Code:
void tokenize ( char * line , char ** words , int * nwords )
{
* nwords =1;
for ( words [0]= strtok ( line , " \t\n" );
(*nwords < MAXWORDS )&&( words[*nwords ]= strtok ( NULL , " \t\n" ));
* nwords =* nwords +1);
return ;
}
I'm not sure how to detect if "cont" is appeared as first word of the line, then tokenize the line.