In C how do I break a multiple word string stored in a variable into an array with each word holding an array value -


what looking have users input of multiple words in 1 variable split apart , each of words stored in array value.

for example user types input of: "when in course" , it's stored in single variable "input"

how each word of variable array such:

array[0] = when array[1] = in array[2] = array[3] = course etc. 

my end goal able run if statement against first word typed , use determine course of action follows.

for example user types: add when in course

and run if statement against it:

if array[0] = add  file_ptr = fopen ("file1.txt", "a+");              fprintf(file_ptr, "%s" , buf," ");                     }             fclose(file_ptr); else if array[0] = delete 

then delete etc.

thank guys assistance.

i don't understand question well, start function first, can split string:

the c library function char *strtok(char *str, const char *delim) breaks string str series of tokens using delimiter delim.

char *strtok(char *str, const char *delim) 

parameters str -- contents of string modified , broken smaller strings (tokens).

delim -- c string containing delimiters. these may vary 1 call another.

source


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -