The science of a little C language has long been forgotten, but do the computer system work to write with C, deeply c memory allocation and string processing too much trouble.
The job needs to cut the string (command) received after the program is run into multiple character arrays (instructions and parameters), and I can't find it on the Internet, and I write a (I don't know if C itself has this function, it can't be found).
Because it is too weak, do not know how to automatically allocate memory, so I set: instruction up to 10, the length of each instruction 50.
The function returns a pointer to a two-dimensional array of characters.
Char**trim (Char*cmd) { Char**argv; Char**RTR; argv= (Char* *) malloc (Ten*sizeof(Char*)); for(inti =0; I <Ten; i++) Argv[i]= (Char*) malloc (sizeof(Char)* -); RTR=argv; inti =0; while(*cmd! =' /'&& *cmd! ='\ n') { if(*cmd! =' ') { * (*argv+i) = *cmd; ++cmd; I++; } Else{i=0; ++cmd; ++argv; while(*cmd = =' ') { ++cmd; } } } returnRTR;}
The C language divides strings by spaces and generates multiple string arrays