Returning char* in function

Posted by Devel on Stack Overflow See other posts from Stack Overflow or by Devel
Published on 2010-03-14T13:18:13Z Indexed on 2010/03/14 13:25 UTC
Read the original article Hit count: 300

Filed under:
|
|

I have function:

char *zap(char *ar) {

    char pie[100] = "INSERT INTO test (nazwa, liczba) VALUES ('nowy wpis', '";
    char dru[] = "' )";
    strcat(pie, ar);
    strcat(pie, dru);
    return pie;
}

and in main there is:

printf("%s", zap( argv[1] )  );

When compiling I get the warning:

test.c: In function ‘zap’:
test.c:17: warning: function returns address of local variable

How should I return char* propertly?

© Stack Overflow or respective owner

Related posts about c

    Related posts about function