I found this sample program which explains the strtok
function:
#include <stdio.h> #include <string.h> int main () { char str[] ="- This, a sample string."; char * pch; printf ("Splitting string \"%s\" into tokens:\n",str); pch = strtok (str," ,.-"); while (pch != NULL) { printf ("%s\n",pch); pch = strtok (NULL, " ,.-"); } return 0; }
However, I don’t see how this is possible to work.
How is it possible that pch = strtok (NULL, " ,.-");
returns a new token. I mean, we are calling strtok
with NULL
. This doesen’t make a lot sense to me.
Related Posts:
- How does strtok() split the string into tokens in C?
- Why do we use NULL in strtok()?
- Implementation of strtok() function
- The difference between n++ and ++n at the end of a while loop? (ANSI C)
- Implementing Taylor Series for sine and cosine in C
- Working on code to calculate cosine with factorial sum
- warning: implicit declaration of function
- pthread_join() and pthread_exit()
- Why should we typedef a struct so often in C?
- What exactly is the difference between “pass by reference” in C and in C++?
- What does “collect2: error: ld returned 1 exit status” mean?
- Floating point exception (core dumped)
- Undefined reference to pthread_create in Linux
- Correct format specifier for double in printf
- dereferencing pointer to incomplete type
- How to convert a string to integer in C?
- Get a substring of a char* [duplicate]
- What is the behavior of integer division?
- Expression must be a modifiable L-value
- Awesomium sdk download
- Bad File Descriptor with Linux Socket write() Bad File Descriptor C
- How do I use valgrind to find memory leaks?
- What is the difference between char s[] and char *s?
- Reading from file using read() function
- What is the difference between ++i and i++?
- warning: assignment makes integer from pointer without a cast
- Error “initializer element is not constant” when trying to initialize variable with const
- munmap_chunk(): invalid pointer
- What is the LD_PRELOAD trick?
- What is the argument for printf that formats a long?
- Cannot assign requested address – possible causes?
- Using %s in C correctly – very basic level
- How do you make an array of structs in C?
- need help understanding the movzbl call in this function
- What is the difference between read and pread in unix?
- What does “control reaches end of non-void function” mean?
- How to create my own header file in c++?
- connect Error: “No route to host”
- warning: implicit declaration of function
- C dynamically growing array
- Returning string from C function
- Why do I get an assertion failure?
- Difference between int32, int, int32_t, int8 and int8_t
- Char Comparison in C
- what is the unsigned datatype?
- lvalue required as left operand of assignment
- how to convert negative hexadecimal to decimal
- Why am I getting “undefined reference to sqrt” error even though I inclu de math.h header?
- Reading a string with scanf
- How to initialize a struct in accordance with C programming language standards
- Expression preceding parentheses?
- Linux equivalent of I_PUSH
- Understanding INADDR_ANY for socket programming
- getopt_long() — proper way to use it?
- C read file line by line
- The Definitive C Book Guide and List[
- When is it a good idea to use strdup (vs malloc / strcpy)
- C read file line by line
- Copying a part of a string (substring) in C
- expression must have integral type
- Incompatible implicit declaration of built-in function ‘malloc’
- Why is %c used in C?
- Need more information about Aborted (core dumped)
- What is Innermost loop in imperfectly nested loops?
- What’s wrong with my code? What is argv[1]?
- What can cause a “Resource temporarily unavailable” on sock send() command
- How to solve error: expected identifier or ‘(‘
- Reversing a string in C
- When a number is written as 0x00… what does the x mean
- How to remove the character at a given index from a string in C?
- waitpid, wnohang, wuntraced. How do I use these
- Split string with delimiters in C
- How to pause in C?
- (.text+0x20): undefined reference to `main’ and undefined reference to function
- Why am I getting this error: “data definition has no type or storage class”?
- I’m getting “Invalid Initializer”, what am I doing wrong?
- Writing binary number system in C code
- Error: initializer element is not computable at load time
- Convert char array to string use C
- warning: passing argument ’from incompatible pointer type [enabled by default]’
- Return a `struct` from a function in C
- Makefile:1: *** missing separator. Stop
- Scanning Multiple inputs from one line using scanf
- Which of sprintf/snprintf is more secure?
- PTHREAD_MUTEX_INITIALIZER vs pthread_mutex_init ( &mutex, param)
- How to concatenate string and int in C?
- execvp: bad address error
- How detect malloc failure?
- A Simple, 2d cross-platform graphics library for c or c++?
- Removing last character in C
- error: ISO C forbids nested functions – What’s wrong?
- Dereference void pointer
- Use of flag in c?
- What primitive data type is time_t? [duplicate]
- Usage of \b and \r in C
- Difference between “while” loop and “do while” loop
- Swapping 2 Bytes of Integer
- GDB no such file or directory
- Parsing command-line arguments in C
- lvalue required as increment operand