why strcat get garbage value
it is just very simple code to concat string by strcat function but at line
second option("values(") change some garbage value instead of "values(".
whats problem i can not understand. i am using cygwin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *insert(char *table, char *value){
char *tmp = "insert into ";
strcat(tmp, table);
strcat(tmp, "values(");
strcat(tmp, value);
strcat(tmp, ")");
return tmp;
}
int main(void) {
puts(insert("login", "test"));
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
return EXIT_SUCCESS;
}
| |
Last edited on
the reason is the tmp
does not point to a memory large enough to hold the appended data. It actally points to a const c string
Topic archived. No new replies allowed.