0

How do I build an array of following type in C?

arr = [['S', 'NP+NP', 'S'],['S', 'NP+NUMBER', 'VP+VERB'],['S', 'VERB', 'NP']]

2 Answers 2

3
char const* arr[][3] = {{"S", "NP+NP", "S"}, {"S", "NP+NUMBER", "VP+VERB"}, {"S", "VERB", "NP"}};
Sign up to request clarification or add additional context in comments.

Comments

0
 const   char *strs[] = {"foo", "bar", "bletch", ...};

and you can access them like this

  for(int i = 0; i < NUMBER_OF_STRINGS; i++) {
        printf("%d: %s\n", i, strs[i]);
    }

3 Comments

it should be const char * or you'll probably have problem when editting it
why this should be constant ? this works fine. the NUMBER_OF_STRINGS should be constance when declaring.
Because "foo", et'al are read-only literals. and NUMBER_OF_STRINGS is actually optional in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.