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 8974587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:42:48+00:00 2026-06-15T18:42:48+00:00

I have seen some examples and tried to do something but now I am

  • 0

I have seen some examples and tried to do something but now I am stuck.

The working code is

    char quality[5][10];
    char * qualities;
    qualities = strtok (message, "\n");
    int k = 0;
    while (qualities != NULL){
        if (k == 0) {
            strcpy(quality[0], qualities);
        }
        else if ( k == 1) {
            strcpy(quality[1], qualities);
        }
        else if ( k == 2) {
            strcpy(quality[2], qualities);
        }
        else if ( k == 3) {
            strcpy(quality[3], qualities);
        }
        else if ( k == 4) {
            strcpy(quality[4], qualities);
        }           
        qualities = strtok (NULL, "\n");
        k++;
    }

However this works with fixed length(in this case just 5), however I would like to assign a variable to quality variable but in that case while loop would not work. What should I do?

  • 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-06-15T18:42:49+00:00Added an answer on June 15, 2026 at 6:42 pm

    Replace this block

    if (k == 0) {
            strcpy(quality[0], qualities);
    } else if ( k == 1) {
        strcpy(quality[1], qualities);
    } else if ( k == 2) {
        strcpy(quality[2], qualities);
    } else if ( k == 3) {
        strcpy(quality[3], qualities);
    } else if ( k == 4) {
        strcpy(quality[4], qualities);
    }
    qualities = strtok (NULL, "\n");
    k++;
    

    with these two lines:

    strcpy(quality[k++], qualities);
    qualities = strtok (NULL, "\n");
    

    This is an equivalent code, but it will work with any number of items, up to the number of elements in the quality array.

    Since the number of elements is fixed, you should change

    while (qualities != NULL)
    

    to

    while (k < N && qualities != NULL)
    

    where N is the number of elements in qualities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen some gridview header freezing examples on the web but I have
I have seen a couple other examples on SO discussing some weird workarounds but
I've seen a bunch of examples but can't seem to get some sample code
Please give me some examples of jump table usage. I have seen this example
I have seen some related questions but none focusing on the specific problem I
i have seen some hand rolled solutions but does jquery out of the box
I have seen some of the other answers on this topic but dont really
I have seen some examples that show that Firefox supports some kind of JavaScript
I've seen this in some topics but haven't fixed my script. I have a
I have seen the same topics here and some topics on other sites, but

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.