hi,
first i ll want to tell you what i am planing to do:
i want to convert a cpp string to a char array
the string gets assembled with x = x + y and wors just fine.
then i want to convert this string into a dynamically sized char array.
Code:
string sFinalQuery;
char *cQuery; // where everything should go at the end.
sFinalQuery = "select * from gpsdestinations where name like '%";
sFinalQuery = sFinalQuery + sMySQLQuery;
sFinalQuery = sFinalQuery + "%' OR beschreibung like '%";
sFinalQuery = sFinalQuery + sMySQLQuery;
sFinalQuery = sFinalQuery + "%'";
cout << sFinalQuery << endl; // test output of the string
printf("\n\nLänge Query : %d\n\n", sFinalQuery.length()); // printing string lenght
cQuery = (char *) malloc(sFinalQuery.length());
for (int i=0; i < sFinalQuery.length(); i++){
cQuery[i] = sFinalQuery[i];
printf("%c", cQuery[i]);
}
printf("\n\nLänge Query : %d\n\n", strlen(cQuery)); // printing array lenght
at the end the lenght from the string and the array are different but they should not be.
may some of you can post a idea why the lenghts are not the same.
i am just going nuts with it.
greez bergziege
ps.: sMySQLQuery is just another string coming from an input device