go through an array in C

I want to increment up where I use a[0]. Something like a++. The only other solution I can think of is a switch case or a bunch of if/else if statement, but that seems inefficient. Is this possible?

#include <stdio.h>
int
main(void)
{
    const char *a[6];    
    a[0]="one";
    a[1]="two";
    a[2]="three";
    a[3]="four";
    a[4]="five";
    a[5]="six";

    for (int i = 0; i < 6; i++)
    {
        printf("This old man, he played %s\nHe played knick-knack on my thumb\nKnick-knack paddywhack, give your dog a bone\nThis old man came rolling home\n\n", a[0]);
    }
}

Answers


What about this?

printf(..., a[i]);

Use a[i].

However that's a very basic question, I'd suggest you to take a look at some tutorial in internet before asking.


You can use a[i] inside the loop to access the ith element.

for (int i=0; i<N; i++)
    printf("%s\n", a[i]);

If you ever have need to increment a pointer inside a loop, you can do it like this:

const char **p=a;
for (int i=0; i<N; i++)
    printf("%s\n", *p++);

Personally, I would use a[i].


Need Your Help

MVC Entity Framework

entity-framework asp.net-mvc-5

I am new to MVC and I'm currently working on a project with an existing database and a web API controller. What is mean't by projecting the data from the Entity Framework instances?