/* This program illustrates reading and parsing command-line input based on whitespace. */ #include #include int main() { const char* whitespace = " \n\r\f\t\v"; char buffer[81]; char* token; /* Start an endless loop. */ while (1) { /* Read in up to 80 characters or until the newline is encountered. */ printf("\nEnter command: "); fgets(buffer, 81, stdin); /* Print the command as entered. */ printf("\nThis is the command as entered: %s\n", buffer); /* Print the command broken into whitespace-delimited tokens. */ printf("\nThis is the command parsed into whitespace-delimited tokens (one per line): \n\n"); token = strtok(buffer, whitespace); while (token != NULL) { printf("%s\n", token); token = strtok(NULL, whitespace); } } return 0; }