In C how can I separate a char array by a delimiter? Or is it better to manipulate a string? What are some good C char manipulation functions?
相关问题
- Multiple sockets for clients to connect to
- how to split a list into a given number of sub-lis
- What is the best way to do a search in a large fil
- How to get the maximum of more than 2 numbers in V
- Faster loop: foreach vs some (performance of jsper
One option is strtok
example:
You want to split it at the space between the two words
you can look this program .First you should use the strtok(input, ",").input is the string you want to spilt.Then you use the strtok(NULL, ","). If the return value is true ,you can print the other group.
You could simply replace the separator characters by NULL characters, and store the address after the newly created NULL character in a new char* pointer:
Note that this code will of course not work if the input string contains more than 9 separator characters.
Look at strtok(). strtok() is not a re-entrant function.
strtok_r() is the re-entrant version of strtok(). Here's an example program from the manual:
Sample run which operates on subtokens which was obtained from the previous token based on a different delimiter:
I came up with this.This seems to work best for me.It converts a string of number and splits it into array of integer:
This is how I do it.