Ask a Question related to UNIX Programming, Design and Development.
-
Hugh Kang #1
Simple question about C program
I am a beginner in C programming. I have a question about C
programming.
In one of our c programs:
char prep_name[18];
char s_time[8];
sprintf(prep_name, "S%s%d%d, s_time, pid, sql_stmt_ctr++);
s_time is alawys 8 characters but pid is 4 ~ 5 and sql_stmt_ctr is
usually
1 ~ 6. We found out that prep_name[] could be over 18 characters when
sql_stmt_ctr is more than 6 digits. We'd like to have just 18
characters
in prep_name even when sql_stmt_ctr is over 6 digits(truncate the rest
digits).
Is there any way to do it?
Regards
Hugh
Hugh Kang Guest
-
Simple Drawing Program with Ruler Scaling?
Hi All, Is there a relatively simple (and reasonably priced) drawing program available for OSX that has scaled rulers (ala MacDraw 2 or early... -
Need Simple Answer to Simple Contribute/Firefox question
Hello all; I've tried the Adobe help in CS3, tech support, phone support, this forum, other forums, Mozilla, and nowhere can I get a straight... -
simple client-server program ??
Hi, how do I develop the following 'simple' program using ASP.NET webforms : a client has a text-file (aaa.txt) that has to be manipulated by... -
need help developing a simple drawing program
I am looking to build a simple drawing program that lets the user make ovals and lines with options to change line width and color. I downloaded an... -
Program Logic Question
Hello All, I have written a little VB program to send packets of data to my web server every 5 seconds in the form of a small csv file. The idea... -
James Antill #2
Re: Simple question about C program
On Tue, 22 Jul 2003 04:50:55 +0200, Måns Rullgård wrote:
Note that this will only have 17 characters and a terminator. This may or> [email]skang@leaguedata.com[/email] (Hugh Kang) writes:
>>>> I am a beginner in C programming. I have a question about C
>> programming.
>> In one of our c programs:
>>
>> char prep_name[18];
>> char s_time[8];
>> sprintf(prep_name, "S%s%d%d, s_time, pid, sql_stmt_ctr++);
>>
>> s_time is alawys 8 characters but pid is 4 ~ 5 and sql_stmt_ctr is
>> usually
>> 1 ~ 6. We found out that prep_name[] could be over 18 characters when
>> sql_stmt_ctr is more than 6 digits. We'd like to have just 18
>> characters
>> in prep_name even when sql_stmt_ctr is over 6 digits(truncate the rest
>> digits).
>> Is there any way to do it?
> snprintf(prep_name, 18, "S%s%d%d, s_time, pid, sql_stmt_ctr++);
may not be what the OP wanted.
I'd worry that truncating sql_stmt_ctr could affect the result, so it
might be better to make sure prep_name is big enough to hold all values.
Also, if you want to use snprintf() it would be much more maintainable
as...
snprintf(prep_name, sizeof(prep_name), "%c%s%lu%u",
s_time, (unsigned long) pid, sql_stmt_ctr++);
--
James Antill -- [email]james@and.org[/email]
Need an efficent and powerful string library for C?
[url]http://www.and.org/vstr/[/url]
James Antill Guest



Reply With Quote

