so I need help separating one string into multiple separate ones. For example, let's say I have something like:
char sentence[]= "This is a sentence.";
and I want to split it to:
char A[]="This";
char B[]="is";
char C[]="a";
char D[]="sentence.";
so I need help separating one string into multiple separate ones. For example, let's say I have something like:
char sentence[]= "This is a sentence.";
and I want to split it to:
char A[]="This";
char B[]="is";
char C[]="a";
char D[]="sentence.";
 
    
    As mentioned you can use strtok() to do this job. The usage is not very intuitive:
char sentence[]= "This is a sentence."; // sentence is changed during tokenization. If you want to keep the original data, copy it.
char *word = strtok( sentence, " ." ); // Only space + full stop for having a multi delimiter example
while (word!=NULL)
{
  // word points to the first part. The end of the word is marked with \0 in the original string
  // Do something with it, process it, store it
  … 
 word = strtok( NULL, " ."); // To get the next word out of sentence, pass NULL
}
