the code is shown below:
sprintf(command, "SELECT * FROM log;");
SQLresult = PQexec(SQLconn, command);
num_tuples = PQntuples(SQLresult);
num_fields = PQnfields(SQLresult);
//PQprint(stdout, SQLresult, SQLprintOpt);
//printf("%d %d\n", num_tuples, num_fields);
for(i = 0; i < num_tuples; i++)
{
for(j = 0; j < num_fields; j++)
{
tempstring = 0;
tempstring = PQgetvalue(SQLresult, i, j);
printf("%s %d %d\n", tempstring, i, j);
strncat(tempstring, "\t", 1);
strcat(filestring, tempstring);
}
strncat(filestring, "\n", 1);
}
printf("%s", filestring);
//fprintf(plogFile, "Who\n");
}
the output looks like
2 4 13:58:33 169.226.2.230
BDF
2 4 13:58:43 169.226.2.230
Who
but should look like
2 3 4 2003-04-15 13:58:33 BDF:
169.226.2.22:/export/applications/mandrake7.0 52
169.226.2.230 /usr/bin/df -k BDF
2 3 4 2003-04-15 13:58:43 USERS: 3 169.226.2.230
who -q Who