By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,367 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

how to split a string without using strtok()

P: 1
can i use strchr() function instead of strtok() function..?
Jun 21 '17 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
strtok returns a "token" which is a group of characters separated by whitespace. Based on that, you can't use strchr since strchr scans for a single character.

You could write your own function that scans a string doing iswhitespace on each character and if not stores the char in a buffer otherwise it appends \0 to the buffer and returns.

You could even return a struct so you could keep track to the start and end position of the token in the string.
Jun 21 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.