Re: init char buffer to null
Re: init char buffer to null
- Subject: Re: init char buffer to null
- From: Sandro Noel <email@hidden>
- Date: Tue, 12 Dec 2006 23:11:46 -0500
Thank you all, this community is GREAT, i'm learning, and you guy's
are just GREAT ... :)
yea, that was a heartfelt moment,
i've been on this problem for 6 hours., ya that sounds stupid,
but i'm used to have an object as string and not have to worry
about terminating my string :)
have a good night !
Sandro.
On 12-Dec-06, at 11:02 PM, Chris Suter wrote:
I believe what he's saying is he's reading a file containing
textual data, e.g. "10\n", and ending up with "103x8dehetkladg..."
because he's not NULL terminating it. So, to the original poster,
while you can get what you want by using calloc instead of malloc
(calloc simply zeroes the memory it gives you, which you can do
manually with memset as well), what you really want to do is fix
the bug whereby you're not NULL terminating what you read. The
easiest way to do that, going off the code above, would be just to
add, after your getBytes:range: call:
buffer[delimiterLocation] = 0
and obviously don't forget to change the malloc line to allocate an
extra character.
- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden