feat: adjust sprintf

This commit is contained in:
dancingCycle 2023-01-18 15:18:10 +01:00
parent daebcb8ce8
commit 9c5776b620
2 changed files with 12 additions and 6 deletions

View File

@ -6,18 +6,24 @@
int main() int main()
{ {
/*'postgresql://begerad:secret@localhost:5432/sib00_vbn_gtfs'*/ /*declaration*/
int cx;
int port = 5432; int port = 5432;
char * user = "begerad"; char * user = "begerad";
char * secret = "secret"; char * secret = "secret";
char * host = "localhost"; char * host = "localhost";
char * db = "vbn_data"; char * db = "vbn_data";
char pqConInfo[100]; const int pqConInfoSize = 100;
char pqConInfo[pqConInfoSize];
printf("main() Started...\n"); printf("main() Started...\n");
cx = snprintf(pqConInfo,pqConInfoSize,"postgresql://%s:%s@%s:%d/%s",user,secret,host,port,db);
sprintf(pqConInfo,"postgresql://%s:%s@%s:%d/%s",user,secret,host,port,db); if(cx>=0 && cx<pqConInfoSize){
printf("main() pqConInfo: %s\n",pqConInfo); printf("main() pqConInfo: %s\n",pqConInfo);
printf("main() cx: %d\n",cx);
}else{
fprintf(stderr,"main() error creating pqConInfo\n");
}
printf("main() Done.\n"); printf("main() Done.\n");
return 0; return 0;
} }

View File

@ -7,7 +7,7 @@ EXE = main
# Compiler, Linker Defines # Compiler, Linker Defines
CC = /usr/bin/gcc CC = /usr/bin/gcc
CFLAGS = -ansi -pedantic -Wall -O2 CFLAGS = -Wall
LIBPATH = -L. LIBPATH = -L.
LDFLAGS = -o $(EXE) $(LIBPATH) $(LIBS) LDFLAGS = -o $(EXE) $(LIBPATH) $(LIBS)
CFDEBUG = -ansi -pedantic -Wall -g -DDEBUG $(LDFLAGS) CFDEBUG = -ansi -pedantic -Wall -g -DDEBUG $(LDFLAGS)