sandbox-c/sprintf/main.c

31 lines
701 B
C
Raw Normal View History

2023-01-18 15:06:39 +01:00
/*use sleep*/
#include <unistd.h>
/*use printf*/
#include <stdio.h>
int main()
{
2023-01-18 15:18:10 +01:00
/*declaration*/
int cx;
2023-01-18 15:06:39 +01:00
int port = 5432;
char * user = "begerad";
char * secret = "secret";
char * host = "localhost";
char * db = "vbn_data";
2023-01-19 08:30:50 +01:00
/*TODO How is const defined?*/
2023-01-18 15:18:10 +01:00
const int pqConInfoSize = 100;
char pqConInfo[pqConInfoSize];
2023-01-18 15:06:39 +01:00
printf("main() Started...\n");
2023-01-18 15:18:10 +01:00
cx = snprintf(pqConInfo,pqConInfoSize,"postgresql://%s:%s@%s:%d/%s",user,secret,host,port,db);
if(cx>=0 && cx<pqConInfoSize){
printf("main() pqConInfo: %s\n",pqConInfo);
printf("main() cx: %d\n",cx);
}else{
fprintf(stderr,"main() error creating pqConInfo\n");
}
2023-01-18 15:06:39 +01:00
printf("main() Done.\n");
return 0;
}