passing text to a function

How do you pass text to a function as it is done in printf? In the prototyping of printf it mentions taking ... as an argument, but how is printf("hello world") handeled? Is hello world read into a temporary array? Thanks in advance.


Comments

  • : How do you pass text to a function as it is done in printf? In the prototyping of printf it mentions taking ... as an argument, but how is printf("hello world") handeled? Is hello world read into a temporary array? Thanks in advance.


    Generally you pass a pointer to the string on the stack.


    Matthew Gross


    URL:http://acheronx.resnet.tamu.edu

  • : How do you pass text to a function as it is done in printf? In the prototyping of printf it mentions taking ... as an argument, but how is printf("hello world") handeled? Is hello world read into a temporary array? Thanks in advance.


    This is copied directly from Turbo C++'s Help:


    #include

    #include


    /* calculate sum of a 0 terminated list */

    void sum(char *msg, ...)

    {

    int total = 0;

    va_list ap;

    int arg;

    va_start(ap, msg);

    while ((arg = va_arg(ap,int)) != 0) {

    total += arg;

    }

    printf(msg, total);

    va_end(ap);

    }


    int main(void) {

    sum("The total of 1+2+3+4 is %d
    ", 1,2,3,4,0);

    return 0;

    }


    I hope that helps. I've never actually made one but this is how it's done.


    -Xotor-


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories