Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Passing String to Function (http://www.velocityreviews.com/forums/t440712-passing-string-to-function.html)

jconnort@rochester.rr.com 12-31-2005 02:54 PM

Passing String to Function
 
I'm sure this is newbie but I've done some searching on this and
haven't found the exact same situation. Basically, I'm trying to pass a
string to a function where it get's built up (it's supposed to be a
where clause for a a database query) and in the called function it
get's built up with malloc as necessary. The problem is, I can't get it
to have the proper value when it comes back to the called function.
Initially, it's just a pointer to char. Can anyone point me to an FAQ
or some such ? Thanks...


Flash Gordon 12-31-2005 03:43 PM

Re: Passing String to Function
 
jconnort@rochester.rr.com wrote:
> I'm sure this is newbie but I've done some searching on this and
> haven't found the exact same situation. Basically, I'm trying to pass a
> string to a function where it get's built up (it's supposed to be a
> where clause for a a database query) and in the called function it
> get's built up with malloc as necessary. The problem is, I can't get it
> to have the proper value when it comes back to the called function.
> Initially, it's just a pointer to char. Can anyone point me to an FAQ
> or some such ? Thanks...


Try changing the * to a ** on line 42. Or, in other words, how can we
tell you what you have done wrong if you don't show us what you have done?

You might find this FAQ useful though:
http://c-faq.com/ptrs/passptrinit.html
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.

Mark McIntyre 01-01-2006 12:06 AM

Re: Passing String to Function
 
On 31 Dec 2005 06:54:14 -0800, in comp.lang.c ,
"jconnort@rochester.rr.com" <jconnort@rochester.rr.com> wrote:

>I'm sure this is newbie but I've done some searching on this and
>haven't found the exact same situation. Basically, I'm trying to pass a
>string to a function where it get's built up


Post some sample of your code. Its impossible to diagnose it via
crystal ball...
Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

clayne 01-01-2006 07:19 AM

Re: Passing String to Function
 
If you're building up a new block block of data based on the contents
of the passed pointer, you shouldn't be using locally defined
(automatic) variables. Instead you should be using malloc to allocate
memory from the heap and return a pointer to the newly allocated area;
or preferably pass an additional argument to your function that is the
address of memory you've allocated for it to store it's results in. The
former lends itself to memory leaks if you're not diligent whereas the
latter usually goes along with better memory management practices
(doesn't mean you are immune to leaking if you forget to free() it as
well, however).



All times are GMT. The time now is 04:30 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.