Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Returning a string array from a function

Reply
Thread Tools

Returning a string array from a function

 
 
Ben Bacarisse
Guest
Posts: n/a
 
      09-09-2007
Army1987 <(E-Mail Removed)> writes:

> On Sat, 08 Sep 2007 16:25:07 +0100, Ben Bacarisse wrote:
>
>>> while(strcmp(ptrlist[i], ""))

>>
>> 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[i]) simpler than while(ptrlist[i][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.

--
Ben.
 
Reply With Quote
 
 
 
 
Adam
Guest
Posts: n/a
 
      09-10-2007
On 8 Sep, 16:25, Ben Bacarisse <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
function returning array of strings shyam C Programming 6 11-26-2007 12:22 PM
returning array of offsets from the Boyer Moore String search algorithm lbrtchx@hotmail.com Java 0 09-04-2007 06:41 PM
returning array of offsets from the Boyer Moore String search algorithm lbrtchx@hotmail.com C Programming 0 09-04-2007 06:41 PM
Returning a 2D array from a function Guha C Programming 1 09-17-2005 12:10 AM
C question: Returning string array from function john C Programming 1 06-29-2004 02:56 AM



Advertisments