sprintf function


 
Thread Tools Search this Thread
Top Forums Programming sprintf function
# 1  
Old 05-01-2006
sprintf function

Hi,
Can someone help me to figure out whether this code is to write file to /tmp/TIMECLOCK directory or just to asign a variable with "/tmp/TIMECLOCK/name.log_copy.pid" as the string?

I am looking into an old C program and could not figure out where in the code that creates /tmp/TIMECLOCK/name.log_copy.pid file except here.

But I thought sprintf only assignes value to string....

==========
sprintf( szfilename, "/tmp/TIMECLOCK/%s.log_copy.%d", n
ame, pid );
==========


Thanks!
# 2  
Old 05-01-2006
You are right. From the man page of sprintf:
Code:
int sprintf(char *s, const char *format, /* [arg,] */ ...);

sprintf() places ``output'', followed by the null character (\0), in
      consecutive bytes starting at *s.  It is the user's responsibility to
      ensure that enough storage is available.

What this code is doing is that it is setting up the string szfilename with "/tmp/TIMECLOCK/<somename>.log_copy.<processid>". The program might use the variable later to open a (possibly) unique file or something.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sprintf and system command in awk

Hello Friends, I'm trying something hard (for me) to create a report script,normally the following script works: Echos are just for cosmetic touch, echo -n "\n-----\t----------\t-------------\t\t--------------\t\t--------\n COUNT\tEVENT_TYPE\tRESPONSE_CODE\t\tINTERNAL_ERROR\t\tFLOWNAME... (7 Replies)
Discussion started by: EAGL€
7 Replies

2. UNIX for Dummies Questions & Answers

Join with awk using sprintf

Hi, Trying to join 2 files with awk (file1 has variable number of fields; file 2 has constant number of fields) file1: hook1|AA|BB|CC|DD hook2|EE|FF file2: hook1|11|22 hook2|33|44 hook3|55|66 output: hook1|11|22|AA|BB|CC|DD hook2|33|44|EE|FF hook3|55|66 What I tried so far:... (3 Replies)
Discussion started by: beca123456
3 Replies

3. Shell Programming and Scripting

[Solved] Not able to quote perl function in sprintf() !

The required form of command is as perl /product/editique/RFR/preproc/scripts/ExprEval.pl -P 'EGAL_CHAINE (" ","")' -K /varsoft/editique/RFR/preproc/logs/D.RFR.PR.PCAC9.PCPA.00.54.20110920.Evaluate_Expression.logWhat's wrong with this code (it is not quoting the function, I have checked... (1 Reply)
Discussion started by: ezee
1 Replies

4. Programming

Problem with Sprintf

Hi, I have the below sample code to hash the input number read from file. File will have 16 to 19 digit number and executable hash the number using some logic and returns the hashed value. Each digit in the 16 digit number is converted to a 4 byte value. That if the input is 16digit integer, the... (6 Replies)
Discussion started by: ramkrix
6 Replies

5. Programming

How to right pad with zeros using sprintf?

I need to right-pad with zeros a string by using (s)printf. I looked up the manual and tried with printf("%-19s", buffer); which right-pad the string with spaces. So I tried printf("%019s", buffer); which left-pad the string with zeros. So I tried both printf("%-019s", buffer);... (9 Replies)
Discussion started by: emitrax
9 Replies

6. Shell Programming and Scripting

Detect sprintf and fprintf bad use

Hello again, I don't know about regexp so I throw this question here: How can I detect files where, for example: sprintf (var1, "hello %s %s", sub1); The problem here is that we have 2 %s and only a variable. Or... the inverse: sprintf (var1, "hello %s %s", sub1, sub2, sub3,...subn); ... (2 Replies)
Discussion started by: albertogarcia
2 Replies

7. Shell Programming and Scripting

printf vs sprintf - perl

I would like to assign the output of printf to a variable in perl , it give me back a "1" instead of the time. How can I stuff the variable with what printf returns? Here is my code: #!/usr/bin/perl $time = localtime(time);... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

8. Shell Programming and Scripting

sprintf result on perl

Hello, In perl lang, I have create a string (@str) by sprintf but unfortunately when program printed it out, only I could saw a number like 1. Certainly printf doesn't problem. How I can convert a string that are result of sprintf to a common string format??! Thanks in advance. PLEASE HELP ME. (2 Replies)
Discussion started by: Zaxon
2 Replies

9. Programming

equivalent of sprintf in C++

Hi My requirement is to convert the following to C++ char buffer; sprintf(buffer,"%s %-50s %6s %-6d %s\n",a.substr(0,5),a.substr(10,20)) Since the buffer is of varying length, i cannot hardcode the value as 90. i would like to convert the buffer to string object so that it can receive any... (1 Reply)
Discussion started by: dhanamurthy
1 Replies

10. Shell Programming and Scripting

ksh scripting sprintf

is there any sprintf function in korn shell scripting, or anything similar to sprintf? (2 Replies)
Discussion started by: gfhgfnhhn
2 Replies
Login or Register to Ask a Question