simple string assignment problem
char stmt_buf[1024], buf[(1024*2)+1];
stmt_buf ="SELECT id, title FROM post LIMIT 5;";
I get an error:
connect2.c: In function ‘main’:
connect2.c:217: error: incompatible types in assignment
jobs
Junior Poster in Training
58 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
Use strcpy() to copy the string.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
A more detailed answer is that C doesn't really have a string type. Because there's no string type, we use arrays of char with a special character acting as the end of the string, and all of the rules for arrays apply. In other words, arrays aren't a first class type that can be assigned, so to copy one array to another, you have to use a loop:
size_t n = strlen ( src );
size_t i;
for ( i = 0; i < n; i++ )
dst[i] = src[i];
dst[i] = '\0';
The strcpy function does that for you, more or less.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401