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

  • SEARCH
  • Home
  • 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 8973009
In Process

The Archive Base Latest Questions

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

I found this program to run through strings and print them. I know there’s

  • 0

I found this program to run through strings and print them. I know there’s an error, but I’m not 100% sure what it is.

char *stringOptions[] = {"one", "two", "three"};

void incrementString(char *input) 
{
    static int i = 0;
    input = stringOptions[i % 3];
    i = (i + 1) % 3;
}

void print_string(void) 
{
    char *string = "initial";
    int i;

    for(i = 0; i < 3; ++i) 
    {
        incrementString(string);
        printf("%s ", string);
    }
}

It is supposed to print out: one two three

Sorry I don’t know more about it, it’s based on something I was trying to do, but I was unsuccessful reading through the strings. It is essential that this be in separate functions like this. Thanks,

  • 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:21:14+00:00Added an answer on June 15, 2026 at 6:21 pm
    input = stringOptions[i % 3];
    

    this doesn’t do anything. Remember, C passes everything by value, so all you’re doing is setting the local copy of input to a new address. You probably want to pass a double pointer into the function and then set the dereferenced version:

    void incrementString(char **input) {
    
    ...
    
    *input = stringOptions[i%3];
    

    then call it like:

    incrementString(&string);
    

    And also what zoidberg said about your loop.

    for(i=0; i < 3; ++i) {
    

    because the second part of a for loop is the condition on which it should continue to loop.

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

Sidebar

Related Questions

http://img136.imageshack.us/img136/3508/texturefailz.png This is my current program. I know it's terribly ugly, I found two
Found this Multimap containing pairs? , but it is not much help How would
I know this type of question has been asked before, but I could not
After doing lot of research in Google, I found this program: #include <stdio.h> int
I was having trouble appending object file in my program. I found this SO
Found This: tyty stack, Social Icons not working with Infinite Scrolling on Wordpress I'm
found this little code snippet that seems to do what i want, but im
Found this: Sub SurroundWithAppendTag() DTE.ActiveDocument.Selection.Text = .Append( + DTE.ActiveDocument.Selection.Text + ) End Sub But
I have written this small program in VS2010 to run on Outlook 2007. It
I have a problem, When I run the following program then I found the

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.