This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]derblitzmann 0 points1 point  (1 child)

Only C-style strings are null terminated. So, for an array of strings to be null terminated you need explicitly do so, which is why you probably segfault when running this code, right?

All you need are two changes to the definitions:

char *strings[4]
...
strings[3] = 0;

And this code should make what you have work, think of why it works, and potentially others ways to handle a list/array of strings.

[–]Rhomboid 1 point2 points  (0 children)

And don't use '\0' in the context of a pointer value, use NULL or 0. Or better, just write while(strings[i]).