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

Need Help How to extract tokens and The current index position inside

P: 1
#include <stdio.h>
#include <string.h>

void string2Lines(char line[], char tokens[]){
char *token_ptr, token[81];
char *i=";" " " "," "." "?" "!";
token_ptr = strtok(line, i );
strcpy(token, token_ptr);
strcat(tokens, strcat(token,"\n"));
token_ptr = strtok(NULL, i );
int main(){
char sentence[81], words[81];
printf("Enter a sentence: ");

How to write a function called findNextToken() that does the same thing as strtok() used above.
It will have three arguments:
(i)The string from which to extract tokens.
(ii)The current index position inside this string at the time of the call. This argument will be sent by reference, since its position will inevitably move past the word that is being extracted.
(iii)The token found, if any. This will return the token the value 1 if a token is found; otherwise it will return 0.
Nov 5 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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