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,
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:
then call it like:
And also what zoidberg said about your loop.
because the second part of a for loop is the condition on which it should continue to loop.