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
here is my tokenize 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 ); } }
I'm not sure how to detect if "cont" is appeared as first word of the line, then tokenize the line.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 ; }



LinkBack URL
About LinkBacks



