05-19-2008
equivalent of sprintf in C++
Hi
My requirement is to convert the following to C++
char buffer[90];
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 number of bytes. So ... i will be converting buffer to string object.
So i need some formatting in C++. Is there any thing similar to sprintf?
Regards
Dhana
10 More Discussions You Might Find Interesting
1. Solaris
********************************
Following is not the real issue. The issue is with popen.
Plz continue forward with the thread to get a better picture.
********************************
Hi,
I am working on a customised ftp application. In it we have used sprintf to store a UNIX command... (7 Replies)
Discussion started by: diganta
7 Replies
2. Programming
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... (1 Reply)
Discussion started by: whatisthis
1 Replies
3. Shell Programming and Scripting
is there any sprintf function
in korn shell scripting,
or anything similar to sprintf? (2 Replies)
Discussion started by: gfhgfnhhn
2 Replies
4. Shell Programming and Scripting
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
5. Shell Programming and Scripting
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
6. Shell Programming and Scripting
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. Programming
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
8. Programming
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
9. UNIX for Dummies Questions & Answers
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
10. Shell Programming and Scripting
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
LEARN ABOUT SUSE
curl_mprintf
curl_printf(3) libcurl Manual curl_printf(3)
NAME
curl_maprintf, curl_mfprintf, curl_mprintf, curl_msnprintf, curl_msprintf curl_mvaprintf, curl_mvfprintf, curl_mvprintf, curl_mvsnprintf,
curl_mvsprintf - formatted output conversion
SYNOPSIS
#include <curl/mprintf.h>
int curl_mprintf(const char *format, ...);
int curl_mfprintf(FILE *fd, const char *format, ...);
int curl_msprintf(char *buffer, const char *format, ...);
int curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...);
int curl_mvprintf(const char *format, va_list args);
int curl_mvfprintf(FILE *fd, const char *format, va_list args);
int curl_mvsprintf(char *buffer, const char *format, va_list args);
int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format, va_list args);
char *curl_maprintf(const char *format, ...);
char *curl_mvaprintf(const char *format, va_list args);
DESCRIPTION
These are all functions that produce output according to a format string and given arguments. These are mostly clones of the well-known C-
style functions and there will be no detailed explanation of all available formatting rules and usage here.
See this table for notable exceptions.
curl_mprintf()
Normal printf() clone.
curl_mfprintf()
Normal fprintf() clone.
curl_msprintf()
Normal sprintf() clone.
curl_msnprintf()
snprintf() clone. Many systems don't have this. It is just like sprintf but with an extra argument after the buffer that
specifies the length of the target buffer.
curl_mvprintf()
Normal vprintf() clone.
curl_mvfprintf()
Normal vfprintf() clone.
curl_mvsprintf()
Normal vsprintf() clone.
curl_mvsnprintf()
vsnprintf() clone. Many systems don't have this. It is just like vsprintf but with an extra argument after the buffer that
specifies the length of the target buffer.
curl_maprintf()
Like printf() but returns the output string as a malloc()ed string. The returned string must be free()ed by the receiver.
curl_mvaprintf()
Like curl_maprintf() but takes a va_list pointer argument instead of a variable amount of arguments.
To easily use all these cloned functions instead of the normal ones, #define _MPRINTF_REPLACE before you include the <curl/mprintf.h> file.
Then all the normal names like printf, fprintf, sprintf etc will use the curl-functions instead.
AVAILABILITY
These function will be removed from the public libcurl API in a near future. They will instead be made "available" by source code access
only, and then as curlx_-prefixed functions. See lib/README.curlx for further details.
RETURN VALUE
The curl_maprintf and curl_mvaprintf functions return a pointer to a newly allocated string, or NULL if it failed.
All other functions return the number of characters they actually outputted.
SEE ALSO
printf(3), sprintf(3), fprintf(3), vprintf(3)
libcurl 7.12 30 April 2004 curl_printf(3)