Do it like this:
char s[256];
strcpy(s, "one two three");
char* token = strtok(s, " ");
while (token) {
printf("token: %s\n", token);
token = strtok(NULL, " ");
}
Note: strtok
modifies the string its tokenising, so it cannot be a const char*
.
More Related Contents:
- split char string with multi-character delimiter in C
- read specific number of chars in c [closed]
- isnt everything where it should be, why the segmentation fault?
- How can I get a text file into a string but whith the “\n” in C?
- String manipulation in C (replace & insert characters)
- returning string in C function [closed]
- Removing trailing newline character from fgets() input
- How do you allow spaces to be entered using scanf?
- How to convert an int to string in C?
- What function is to replace a substring from a string in C?
- Stringification of a macro value
- Why is “a” != “a” in C?
- Is the strrev() function not available in Linux?
- Is it possible to modify a string of char in C?
- Using strtok() in nested loops in C?
- Difference between char *str=”STRING” and char str[] = “STRING”?
- How to compare strings in an “if” statement? [duplicate]
- fgets() includes the newline at the end [duplicate]
- Why doesn’t scanf need an ampersand for strings and also works fine in printf (in C)?
- How do I print a non-null-terminated string using printf?
- What is the proper way of implementing a good “itoa()” function?
- string array with garbage character at end
- Comparing two strings in C? [duplicate]
- Why is adding a leading space in a scanf format string recommended?
- Conversion of Char to Binary in C
- Modify a string with pointer [duplicate]
- How can I convert an int to a string in C?
- realloc(): invalid next size when reallocating to make space for strcat on char * [duplicate]
- C -> sizeof string is always 8
- Reading newline from previous input when reading from keyboard with scanf()