sprintf

sprintf in Delphi?

Hi there! Does anyone know a 100% clone of the C/C++ printf for Delphi? Yes, I know the System.Format function, but it handles things a little different. For example if you want to format 3 to "003" you need "%03d" in C, but "%.3d" in Delphi. I have an application written in Delphi which has to be able to format numbers using C format...

Recovering graceflly from a failed vsnprintf on msvc2008

I'm looking for a way to use some variant of vsnprintf() with a buffer that can possibly be longer than the input buffer without triggering an error to the user. So far I've found that vsnprintf() and its variants silently truncate the string when the buffer is too small but they don't return the actual length of the string so I can't t...

Is there a default buffer length for 'sprintf' method?

Hi, I used sprintf method to format data to a string which I want to write to a file, in C++ console application using VS 2008. The Input is a particular message, which has various variables and values (ex: Type 'int' and Value '10' / Type string and value "abc", etc.) When I send a two messages it works perfectly. But When I send more ...

sprintf and % signs in text

A problem I recently ran into was that when trying to update a field in my database using this code would not work. I traced it back to having a % sign in the text being updated ($note, then $note_escaped)... Inserting it with sprintf worked fine though. Should I not be using sprintf for updates, or should it be formed differently? I d...

Changing the order of arguments in ruby sprintf

Is it possible to change the order of parameters to sprintf? like sprintf(" this is %arg[2] test %arg[1]" , arg1, arg2) I need to dynamically change the order of the arguments so is that possible with sprintf? ...

How to append strings using sprintf ?

Hey everybody, Thank you all before I start. I am facing a serious issue with sprintf. suppose my code snippet is : sprintf(Buffer,"Hello World"); sprintf(Buffer,"Good Morning"); sprintf(Buffer,"Good Afternoon"); . . . Some hundred sprints.... If i do like this, its getting overwritten. How can I avoid overwritting using sprint...

Is there a sprintf equivalent for node.js

Looking to do output formatting (sprintf type functionality) in node.js, but before I write it myself I was wondering if there's something similar built-in (I've trawled the docs to no avail) or if someone's already written a module. Many thanks ...

Warning: sprintf() [function.sprintf]: Too few arguments in /home/inrunitc/public_html/chek/chek.php on line 132

Warning: sprintf() [function.sprintf]: Too few arguments in /home/inrunitc/public_html/chek/chek.php on line 132 Query was empty I am new to PHP and mysql and I have like 88 fields in my form - what should I do ? ...

C: sprintf and recursion

In C, is it possible to use recursion within the sprintf function ? For some reason I get a segmentation fault when I do it: inline char *TreeNode_toString(const TreeNode *node) { char *out; if(TreeNode_isExternal(node)) // If the node has no children... { sprintf(out, "%s:%.2f", node->name, node->distance); } else // The...

fill a buffer successively

i intend to fill a char-pointer array successively in a for-loop. the content to fill in is a integer so i need to cast. but i didn't get the result i want to.. for (i=0;i<max0;i++){ sprintf(buf, "%d", content[i]); } sprintf replaces the hole buf, but i want to append. for (i=0;i<max0;i++){ buf[i]=(char) contint[i] } but th...

PHP function problem

Hello, i have this little script, which should ping the IPs in the $hosts_to_ping array. This PHP is called with JS in the index.html. But something is wrong, because the $rval is always 1 (which mean the host is unreachable). But i know that the first two host is alive. So I print the $res variable, and i see the message: Need to gi...

Creating a fixed length output string with sprintf containing floats

Hi, I'm trying to create a file which has the following structure: - Each line has 32 bytes - Each line looks like this format string: "%10i %3.7f %3.7f\n" My Problem is the following: When i have a negative floating point numbers the line gets longer by one or even two characters because the - sign does not count to the "%3.7f". Is...

When and why can sprintf fail?

I'm using swprintf to build a string into a buffer (using a loop among other things). const int MaxStringLengthPerCharacter = 10 + 1; wchar_t* pTmp = pBuffer; for ( size_t i = 0; i < nNumPlayers ; ++i) { const int nPlayerId = GetPlayer(i); const int nWritten = swprintf(pTmp, MaxStringLengthPerCharacter, TEXT("%d,"), nPlayerId);...

C++ convert formatted string to a stream

Hi All, I'm using VS2008 C++. As I understand it there is no way to pass something like this in a C++ stream : (without using external libraries) "number " << i <------ when i is an integer. So I was looking for a better way to do this, and I all I could come up with is create a string using : char fullstring = new char[10]; spr...

printf, sprintf print at least two decimal places

I'm trying to figure out how to use sprintf to print at least two decimal places and no leading zeros. For instance input: 23 23.0 23.5 23.55 23.555 23.0000 output: 23.00 23.00 23.50 23.55 23.555 23.00 any formatting help would be appreciated ...

Translating C++'s sprintf format string to C#'s string.Format

I found the following C++ code (comments added myself): // frame_name is a char array // prefix is std::string // k is a for loop counter // frames is a std::vector string sprintf(frameName, "%s_%0*s.bmp", prefix.c_str(), k, frames[k].c_str()); I then try to translate it to C# // prefix is string // k is a for loop counter // frames ...

C language - Fscanf and sprint commands in unix environment

I am trying to read file with 30 rows and 5 columns with separator of "tab". Each time I get only part of the rows. In the windows environment it's working good. Any idea why in unix it is not working? while (fscanf(FFMapFile, "%s\t%s\t%s\t%s\t%s\t", fnfMap[i].COS_ID, fnfMap[i].FF_First_Act, fnfMap[i].FF_Next_Act, nfMap[i].Free_FF_allo...

Converting a void* to a std::string

After perusing the web and messing around myself, I can't seem to convert a void*'s target (which is a string) to a std::string. I've tried using sprintf(buffer, "%p", *((int *)point)); as recommended by this page to get to a C string, but to no avail. And sadly, yes, I have to use a void*, as that's what SDL uses in their USEREVENT stru...

C: sprintf leads to SIGSEGV core via an strlen

Hi, My C application has the following two lines: char buf[1024]; sprintf(buf, "%s/game/rabbit/habit/cmd/talkPipe", getenv("APPLICATION_PATH")); The application sporadically crashes with SIGSEGV in the following manner: strlen(ff2ba231, 0, ffbfe1d0, 10, 7fff24d7, 0)+0x50 sprintf(ffbfe2a4, ff2ba231, 0, 74656400, 12, ff362ef2)+0x24 Ra...

C, sprintf and "sum" of string and int

Hi, I didn't used C for a lot of time, and now I have to modify a little piece of code. There one thing I can't understand: char filename[20]; filename[0] = '\0'; for (j=0; j < SHA_DIGEST_LENGTH; j++){ sprintf(filename + strlen(filename),"%02x",result[j]); } In the first line a string of 20 characters is dleclared. In the second li...