Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,700 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,482 people online right now. Registration is fast and FREE... Join Now!




strtk() access 2nd token

 
Reply to this topicStart new topic

strtk() access 2nd token, I can access 1st token, how do I access 2nd token?

trista
post 12 Oct, 2006 - 01:41 PM
Post #1


New D.I.C Head

*
Joined: 1 Oct, 2006
Posts: 12


My Contributions


I figured out how to access and process the first token, but I want to check and see if the 2nd token is a digit. How do I access it? I have read that to access the 2nd token, another strtok() call must be used. I tried it and how I have my code doesn't work:

CODE

void lineEditor::processLine(char *newString)
{
  char *temp; // = NULL;

  strcpy(tempString, newString);
  temp = strtok(tempString, " ");

  if(isCommand(temp))
    {
      com = *temp;   //this part works
    }
  temp = strtok(NULL, tempString, " "); //this is where trouble starts
   if(isdigit(temp))
    {
      curLine = atoi(*temp);  //doesn't work
      cout << "CurLine in processLine is: " << curLine << endl; //just a test
      }
  else
    {
      insertLine(newString);
    }
  
}  



my isdigit() is wrong also. Any ideas?

Trista
User is offlineProfile CardPM

Go to the top of the page

gregoryH
post 13 Oct, 2006 - 01:14 AM
Post #2


D.I.C Regular

Group Icon
Joined: 4 Oct, 2006
Posts: 417



Dream Kudos: 50
My Contributions


trista, try this idea...

assume tempString = "trista greg john"
CODE
temp = strtok(tempString, " "); // temp = trista
temp = strtok(NULL, " "); // now temp = greg


This post has been edited by gregoryH: 13 Oct, 2006 - 05:32 PM
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 09:01AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month