Search Results

Search found 266 results on 11 pages for 'sprintf'.

Page 1/11 | 1 2 3 4 5 6 7 8 9 10 11  | Next Page >

  • How to append strings using sprintf ?

    - by rejinacm
    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 sprintf. If i give a printf at the end i want to see all the lines. How to xchieve this.

    Read the article

  • Creating a fixed length output string with sprintf containing floats

    - by Kungi
    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 there any way to do this more nicely than this? if( node->lng > 0 && node->lat > 0 ) { sprintf( osm_node_repr, "%10i %3.7f %3.7f\n", node->id, node->lng, node->lat ); } else if (node->lng > 0 && node->lat < 0) { sprintf( osm_node_repr, "%10i %3.7f %3.6f\n", node->id, node->lng, node->lat ); } else if (node->lng < 0 && node->lat > 0) { sprintf( osm_node_repr, "%10i %3.6f %3.7f\n", node->id, node->lng, node->lat ); } else if ( node->lng < 0 && node->lat < 0 ) { sprintf( osm_node_repr, "%10i %3.6f %3.6f\n", node->id, node->lng, node->lat ); } Thanks for your Answers, Andreas

    Read the article

  • Problem with sprintf function, last parameters are wrong when written

    - by Apoc
    So I use sprintf sprintf(buffer,"%f|%f|%f|%f|%f|%f|%d|%f|%d", x, y, z, u, v, w, nID,dDistance, nConfig) But when I print the buffer I get the 2 last parameters wrong, they are lets suppose to be 35.0000 and 0 and in the string they are 0.00000 and 10332430 and my buffer is long enough and all the other parameters are good in the string Any idea? Is there a length limit to sprintf or something^ I checked the types of all the numbers and they are right, but what seems to be the problem is the dDistance. When I remove it from the sprint, the nConfig gets the right value in the string, but when I remove nConfig, dDistance still doesn't get the right value. I checked and dDistance is a double. Any idea? Since people don't seem to believe me I did this : char test[255]={0}; int test1 = 2; double test2=35.00; int test3 = 0; sprintf(test,"%d|%f|%d",test1,test2,test3); and I get this in my string: 2|0.000000|1078034432

    Read the article

  • C: sprintf and recursion

    - by Shinka
    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 node is strictly binary, so it will have two non-null children { char *l = TreeNode_toString(node->l); // l = left child char *r = TreeNode_toString(node->r); // r = right child sprintf(out, "(%s,%s):%.2f", l, r, node->distance); } return out; }

    Read the article

  • sprintf and % signs in text

    - by Cameron Conner
    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 did some searching but couldn't come up with anything. $id = mysql_real_escape_string($id); $note_escaped = mysql_real_escape_string($note); $editedby = mysql_real_escape_string($author); $editdate = mysql_real_escape_string($date); //insert info from form into database $query= sprintf("UPDATE notes_$suffix SET note='$note_escaped', editedby='$editedby', editdate='$editdate' WHERE id='$id' LIMIT 1"); Thanks much!

    Read the article

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

    - by thebackup
    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 is List<string> string frameName = string.Format("{0}_(what goes in here?).bmp", prefix, k, frames[k]); Basically, what would be the C# equivalent of the C++ format string "%s_%0*s.bmp"?

    Read the article

  • sprintf in Delphi?

    - by kroimon
    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 strings, so do you know a snippet/library for that? Thanks in advance!

    Read the article

  • When and why can sprintf fail?

    - by Srekel
    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); assert(nWritten >= 0 ); pTmp += nWritten; } *pTaskPlayers = '\0'; If during testing the assert never hits, can I be sure that it will never hit in live code? That is, do I need to check if nWritten < 0 and handle that, or can I safely assume that there won't be a problem? Under which circumstances can it return -1? The documentation more or less just states "If the function fails". In one place I've read that it will fail if it can't match the arguments (i.e. the formatting string to the varargs) but that doesn't worry me. I'm also not worried about buffer overrun in this case - I know the buffer is big enough.

    Read the article

  • sprintf() to truncate and not round a float to x decimal places?

    - by jerrygarciuh
    Hi folks, When calculating a golf handicap differential you are supposed to truncate the answer to 1 decimal place without rounding. No idea why but... I know how to do this using TRUNCATE() in mySQL SELECT TRUNCATE( 2.365, 1 ); // outputs 2.3 but I was wondering if sprintf() could do this? The only way I know to work with decimal places in a float is ... echo sprintf("%.1f", 2.365); // outputs 2.4 TIA JG

    Read the article

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

    - by Isuru
    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 than two messages it gives a runtime error saying 0xC0000005: Access violation reading location 0xabababab. Why is this happening? Is it because the method 'sprintf' has a default buffer length? How can I overcome this problem?

    Read the article

  • How to use sprintf instead of hardcoded values

    - by astha goyal
    I am developing a firewall for Linux as my project. I am able to capture packets and to block them. I am using IPTABLES. How can I use variables with sprintf instead of hardcoded values? sprintf(comm, "iptables -A INPUT -s $str -j DROP") // inplace of: sprintf(comm, "iptables -A INPUT -s 192.168.0.43 -j DROP")

    Read the article

  • sprintf bug with php & apache in windows?

    - by potatoe
    I've run into a strange problem on a WAMP server setup (PHP version 5.3.0, Apache 2.2.11). When using sprintf to output a number, I occasionally get erroneous characters in the output string. Example: (not trimmed from anything, this is the only code in the script) $dt1 = new DateTime('now'); $dt2 = new DateTime('now - 10 min'); $interval = $dt1->diff($dt2); $number = 10.0; $string = sprintf("%.1f", $number); echo "number: $number, string: $string\n"; If I run this at the command prompt with PHP CLI, I get the expected output: number: 10, string: 10.0 However, if I serve it using Apache, in the browser I get number: 10, string: :.0 with a colon where '10' should be. (Note that ':' is the next ascii character in sequence after '9', if $number is 0-9, everything works. Numbers greater than 10 appear to use ascii equivalents - so 11 is ';', 12 is '<', etc.) The strangest part is that the first four lines in the above code sample seem to affect the results. Logically, those statements should have no impact, but if I comment them out or remove them the problem goes away. Any ideas? Anyone else able to replicate this?

    Read the article

  • sprintf an LPCWSTR variable

    - by Julio
    Hello everyone. I'm trying to debug print an LPCWSTR string, but I get a problem during the sprintf push in the buffer, because it retrieve only the first character from the string. Here is the code: HANDLE WINAPI hookedCreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { char buffer[1024]; sprintf_s(buffer, 1024, "CreateFileW: %s", lpFileName); OutputDebugString(buffer); return trueCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwFlagsAndAttributes, dwCreationDisposition, hTemplateFile); } For example I get "CreateFileW: C" or "CreateFileW: \". How do I properly push it in the buffer? Thank you.

    Read the article

  • strod() and sprintf() inconsistency under GCC and MSVC

    - by Dmitry Sapelnikov
    I'm working on a cross-platform app for Windows and Mac OS X, and I have a problem with two standard C library functions: strtod() (string-to-double conversion) ? sprintf (when used for outputting double-precision floating point numbers) -- their GCC and MSVC versions return different results. I'm looking for a well-tested cross-platform open-source implementation of those functions, or just for a pair of functions that would correctly and consistently convert double to string and back. I've already tried the clib GCC implementation, but the code is too long and too dependent on other source files, so I expect the adaptation to be difficult. What implementations of string-to-double and double-to-string functions would you recommend?

    Read the article

  • strtod() and sprintf() inconsistency under GCC and MSVC

    - by Dmitry Sapelnikov
    I'm working on a cross-platform app for Windows and Mac OS X, and I have a problem with two standard C library functions: strtod() - string-to-double conversion sprintf() - when used for outputting double-precision floating point numbers) Their GCC and MSVC versions return different results. I'm looking for a well-tested cross-platform open-source implementation of those functions, or just for a pair of functions that would correctly and consistently convert double to string and back. I've already tried the clib GCC implementation, but the code is too long and too dependent on other source files, so I expect the adaptation to be difficult. What implementations of string-to-double and double-to-string functions would you recommend?

    Read the article

  • fill a buffer successively

    - by mkind
    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 this isn't working too. it seems to me, i get ascii-code of the content[i].

    Read the article

  • Using pinvoke in c# to call sprintf and friends on 64-bit

    - by bde
    I am having an interesting problem with using pinvoke in C# to call _snwprintf. It works for integer types, but not for floating point numbers. This is on 64-bit Windows, it works fine on 32-bit. My code is below, please keep in mind that this is a contrived example to show the behavior I am seeing. class Program { [DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] private static extern int _snwprintf([MarshalAs(UnmanagedType.LPWStr)] StringBuilder str, uint length, String format, int p); [DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] private static extern int _snwprintf([MarshalAs(UnmanagedType.LPWStr)] StringBuilder str, uint length, String format, double p); static void Main(string[] args) { Double d = 1.0f; Int32 i = 1; Object o = (object)d; StringBuilder str = new StringBuilder(); _snwprintf(str, 32, "%10.1f", (Double)o); Console.WriteLine(str.ToString()); o = (object)i; _snwprintf(str, 32, "%10d", (Int32)o); Console.WriteLine(str.ToString()); Console.ReadKey(); } } The output of this program is 0.0 1 It should print 1.0 on the first line and not 0.0, and so far I am stumped.

    Read the article

  • How to implement " char * ftoa(float num) " without sprintf() library function in C, C++ and JAVA

    - by SIVA
    Today I appeared for an interview, and the question was writing my own "char * ftoa(float num) " in C, C++ and Java. Yes, I know float numbers follow IEEE standard while allocating their memory, but I don't know float to char conversion by using Mantissa and Exponent in C. I don't have any idea to solve the above problem in C++ and JAVA. I/P to the ftoa(): 1.23 O/P from the ftoa(): 1.23 (char format). Thanks in advance ...

    Read the article

  • Sprintf equivalent in Mathematica?

    - by jxy
    I don't know why Wikipedia lists Mathematica as a programming language with printf. I just couldn't find the equivalent in Mathematica. My specific task is to process a list of data files with padded numbers, which I used to do it in bash with fn=$(printf "filename_%05d" $n) The closest function I found in Mathematica is PaddedForm. And after some trial and error, I got it with "filename_" <> PaddedForm[ Round@#, 4, NumberPadding -> {"0", ""} ]& It is very odd that I have to use the number 4 to get the result similar to what I get from "%05d". I don't understand this behavior at all. Can someone explain it to me? And is it the best way to achieve what I used to in bash?

    Read the article

1 2 3 4 5 6 7 8 9 10 11  | Next Page >