Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7577757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:16:10+00:00 2026-05-30T17:16:10+00:00

Say I have three c-style strings, char buf_1[1024] , char buf_2[1024] , and char

  • 0

Say I have three c-style strings, char buf_1[1024], char buf_2[1024], and char buf_3[1024]. I want to tokenize them, and do things with the first token from all three, then do the same with the second token from all three, etc. Obviously, I could call strtok and loop through them from the beginning each time I want a new token. Or alternatively, pre-process all the tokens, stick them into three arrays and go from there, but I’d like a cleaner solution, if there is one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:16:12+00:00Added an answer on May 30, 2026 at 5:16 pm

    It sounds like you want the reentrant version of strtok, strtok_r which uses a third parameter to save its position in the string instead of a static variable in the function.

    Here’s some example skeleton code:

    char buf_1[1024], buf_2[1024], buf_3[1024];
    char *save_ptr1, *save_ptr2, *save_ptr3;
    char *token1, *token2, *token3;
    
    // Populate buf_1, buf_2, and buf_3
    
    // get the initial tokens
    token1 = strtok_r(buf_1, " ", &save_ptr1);
    token2 = strtok_r(buf_2, " ", &save_ptr2);
    token3 = strtok_r(buf_3, " ", &save_ptr3);
    
    while(token1 && token2 && token3) {
        // do stuff with tokens
    
        // get next tokens
        token1 = strtok_r(NULL, " ", &save_ptr1);
        token2 = strtok_r(NULL, " ", &save_ptr2);
        token3 = strtok_r(NULL, " ", &save_ptr3);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have three files (template_*.txt): template_x.txt template_y.txt template_z.txt I want to copy them
Let's say I have the following three strings: (section1){stuff could be any character, i
Say I have three classes: class X{}; class Y{}; class Both : public X,
Say I have three tables: Fruit (Table 1) ------ Apple Orange Pear Banana Produce
Let's say you have three tables named Item, Event, and Seat, constructed as such:
Let's say I have the three following lists A1 A2 A3 B1 B2 C1
Lets just say that I have three textboxes: TextBox1, TextBox2, TextBox3. Normally if I
Say I have a query like this: one two three, if I replace with
Lets say I have one row with three columns - some buttons on left
Let's say I have a style sheet dt{ width=15%; } dt x{ background-color:red; ????

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.