Returning a string array from a function

B

Ben Bacarisse

Army1987 said:
while(strcmp(ptrlist, ""))


This test would be simpler with a NULL as the end marker.

I agree that it is silly to use an empty string as a sentinel, but
how is while(ptrlist) simpler than while(ptrlist[0])?


True. I forgot that I had already explained how to remove the strcmp
call!

Of course, it *is* simpler by almost any measure, but I won't argue
the point -- I know exactly what you mean. Once the function call has
been replaced the two test are essentially equivalent.
 
A

Adam

It would be more idiomatic to use NULL for the final sentinel value
and even more idiomatic to return the number of strings and have no
sentinel.

After a bit of exploration, I've altered the function to return the
number of strings.

[snip other helpful comments]

Thanks to all who provided advice, I've got my function working now
and have learned more about indirection and char arrays in the
process. :)

Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top