String arrays

Alright, I'm wanting to create an array of strings of letter grades in C. But, it's not giving me the correct results. Here's a sample of how I do it:

char letters[13][2] = {"A+", "A", "A-"};

But when I print the first letter (printf("%s", letters[0]);), it actually prints A+A instead of just A+.

Is there a way around this?
Modify your array definition to accommodate the string terminating null character.

char letters[13][3] = {"A+", "A", "A-"};

This is the prime reason why you should go for vectors.
Last edited on
Topic archived. No new replies allowed.