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?
Your best bet probably is not to return it at all – instead, pass the buffer you want to populate into the function as a parameter.
Then call it like this:
To bullet proof this function, you also need to pass in the length for the buffer, and then check against this every time you are about to add a new query element.