con este script te podes conectar, esto es básico, vos le agregas el nivel de complejidad que necesitas.
saludos
#include <stdio.h>
#include <libpq-fe.h>
#include <iostream>
#include <fstream>
static void
salir(PGconn *psql)
{
PQfinish(psql);
exit(1);
}
int
main()
{
PGconn *psql;
PGresult *result;
int nFields;
int i,j;
psql = PQconnectdb("hostaddr = '10.20.182.13' port = '5432' dbname = 'apl_calden2' user = 'postgres' password = 'manager' conn
ect_timeout = '10'");
if (PQstatus(psql) != CONNECTION_OK)
{
fprintf(stderr, "libpq error: PQstatus(psql) != CONNECTION_OK\n\n");
salir(psql);
}
result = PQexec(psql,"select * from empresa;");
nFields = PQnfields(result);
if (nFields != 0){
for (i = 0; i < nFields; i++)
printf("%-15s", PQfname(result, i));
printf("\n\n");
for (i = 0; i < PQntuples(result); i++)
{
for (j = 0; j < nFields; j++)
printf("%-15s", PQgetvalue(result, i, j));
printf("\n");
}
PQclear(result);
}
salir(psql);
}