The problem is returned value SQLStatement from function. It is generated exactly in the way I wanted (checked in the debug mode), but when I call the function in the main(), there is a garbage as returned value. Function and sample code is given below:
char *GenerateSQLStatement(char *SQLQuery){
size_t SQLQueryCounter = 0;
size_t TableNameCounter = 0;
size_t CVIQueryConstantCounter = 0;
while(SQLQuery[SQLQueryCounter] != '\0') SQLQueryCounter++;
while(TableName[TableNameCounter] != '\0') TableNameCounter++;
while(CVIQueryConstant[CVIQueryConstantCounter] != '\0') CVIQueryConstantCounter++;
char SQLStatement [CVIQueryConstantCounter + TableNameCounter + SQLQueryCounter + 1];
for (int i = 0; i <= (CVIQueryConstantCounter + TableNameCounter + SQLQueryCounter); i++) SQLStatement[i] = '\0';
strcat(SQLStatement, CVIQueryConstant);
strcat(SQLStatement, TableName);
strcat(SQLStatement, SQLQuery);
return SQLStatement;
}
void main(){
char *SQLStatement = GenerateSQLStatement("test");
}
Any ideas what's wrong?