Passing String to Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jconnort@rochester.rr.com

    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

    #2
    Re: Passing String to Function

    jconnort@roches ter.rr.com wrote:[color=blue]
    > 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...[/color]

    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:

    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.

    Comment

    • Mark McIntyre

      #3
      Re: Passing String to Function

      On 31 Dec 2005 06:54:14 -0800, in comp.lang.c ,
      "jconnort@roche ster.rr.com" <jconnort@roche ster.rr.com> wrote:
      [color=blue]
      >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[/color]

      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 =----

      Comment

      • clayne

        #4
        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).

        Comment

        Working...