Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aarplane

macrumors newbie
Original poster
Hey guys,

I'd like to make an array of strings in C, but I'm unsure of how to do so.

Entries in this array will be output-ed to a field on a form.

Thanks in advance!
 
There are a number of ways to do this. One way, if you just want to output various strings is this:

Code:
const char *out[] = {"string1", "string2", "string3"};
printf("%s\n", out[1]);

Another, if you're asking for strings, is this:
Code:
char input[10][200];
scanf("%s", &input[3]);
 
Another, if you're asking for strings, is this:
Code:
char input[10][200];
scanf("%s", &input[3]);

Careful! input[3] is already a char*, so the extra ampersand is spurious. Also, this code is asking for a buffer overrun. If you must use scanf, at least tell it you don't want more than 199 characters (leaving room for the terminating null character):

Code:
scanf("%199s", input[3]);
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.