printf

Why doesn't Perl print the last text before it exits?

My code won't run the last line right before " exit; " and I have no clue why. I tried to put an additional printf $fh line before exit, but that didn't work either; it would not print either line. Everything else prints fine except the last print statements before the exit. Any clue why this happens? Or better yet, how to fix or wor...

the buffer and output sequence of cout and printf

I know cout and printf have buffer today, and it is said that the buffer is some like a stack and get the output of cout and printf from right to left, then put them out(to the console or file)from top to bottem. Like this, a = 1; b = 2; c = 3; cout<<a<<b<<c<<endl; buffer:|3|2|1|<- (take “<-” as a poniter) output:|3|2|<- (output ...

When pipes are in place and have overwritten stdout and stderr, where does printf go?

I have set up pipes to redirect stderr and stdout. When I use printf, does it send data to stdout or to stream 1? If it sends it to stdout, how can I instead configure it to send data to stream 1? ...

Why do NSString and NSLog appear to handle %C and %lc (and %S and %ls) differently?

Apple's String Format Specifiers document claims, The format specifiers supported by the NSString formatting methods and CFString formatting functions follow the IEEE printf specification; … You can also use these format specifiers with the NSLog function. But, while the printf specification defines %C as an equivalent for %lc and ...

Display the binary representation of a number in C?

Still learning C and I was wondering: Given a number, is it possible to do something like the following? char a = 5; printf("binary representation of a = %b",a); > 101 Or would i have to write my own method to do the transformation to binary? ...

sprintf outcome problem

Here is my code: <?php $variable1 = 00001; $variable2 = (sprintf('%04d', $variable1 + 1)); echo $variable2; ?> How come the outcome of this code is "0002" and not "00002"? in other words it is missing a 0. ...

Strange code crash problem?

I have a MSVC 6.o workspace, which has all C code. The code is being run without any optimization switch i.e with option O0, and in debug mode. This code is obtained from some 3rd party. It executes desirable as it is. But when I add some printf statements in certain functions for debugging, and then execute the code, it crashes. I sus...

printfs inside a shared object (dynamic library) not getting printed

Hello, I have a shared object which i create on windows using Real View developer suite tool linked command on windows host- armlink -o mylib.so <"my *.o files given here"> Then i link an application with this mylib.so shared library on linux using gcc tools. I have printf statements inside functions in this mylib.so, but when I run...

Why does Mac's $find not have the option -printf?

I have not found a reason why Mac's find does not have the option -printf. Apple normally decides to take options out which are not orthogonal to the other commands? How can you reach the same result as the following command in Mac without coreutils? find . -printf "%i \n" // command in Ubuntu ...

How do I align a number like this in C?

I need to align a series of numbers in C with printf() like this example: -------1 -------5 ------50 -----100 ----1000 Of course, there are numbers between all those but it's not relevant for the issue at hand... Oh, consider the dashes as spaces, I used dashes so it was easier to understand what I want. I'm only able to do this: --...

What should I use instead of printf in Perl?

I need to use some string replacement in Perl to ease translations, i.e. replace many print "Outputting " . $n . " numbers"; by something like printf ("Outputting %d numbers", $n); However, I'd like to replace printf with something easier to parse for humans, like this: printX ("Outputting {num} numbers", { num => $n }); or gene...

PHP printf not printing, simplexml_load_string not parsing

I have some data that won't printf.... echo works, but not printf There is data in the string, also simplexml_load_string won't parse the string. There is some binary or invisible character that I cannot see and can't get the ordinal value for that is causing printf to fail as well as most other string functions in PHP. Clearly this ...

In F#, How do I customize output of a custom type using printf?

I've read through a good chunk of Expert F# and am working on building an actual application. While debugging, I've grown accustomed to passing fsi commands like this to make things legible in the repl window: fsi.AddPrinter(fun (x : myType) -> myType.ToString()) I would like to extend this to work with the printf formatter, so I cou...

Why is String's format(Object... args) defined as a static method?

I wonder why Java 5 and above provide a printf-style formatter using a static method in class String like this: public static String format(String format, Object... args) instead of public String format(Object... args) so that we can write "%02d".format(5) to get 05 instead of String.format("%02d", 5). I imagined if I could modi...

Only show decimal point if floating point component is not .00 sprintf/printf

I am pretty formatting a floating point number but want it to appear as an integer if there is no relevant floating point number. I.e. 1.20 -> 1.2x 1.78 -> 1.78x 0.80 -> 0.8x 2.00 -> 2x I can achieve this with a bit of regex but wondering if there is a sprintf-only way of doing this? I am doing it rather lazily in ruby like so: ("...

What does floating point error -1.#J mean?

Recently, sometimes (rarely) when we export data from our application, the export log contains float values that look like "-1.#J". I haven't been able to reproduce it so I don't know what the float looks like in binary, or how Visual Studio displays it. I tried looking at the source code for printf, but didn't find anything (not 100% s...

What is the Java equivalent of C's printf %g format specifier?

I tried using Formatter.format, but that seems to leave the mantissa on numbers with 0 mantissa, whereas the C version does not. Is there an equivalent of C's %g format specifier in Java, and if not, is there a way to fake it? My intention is to preserve the mantissa exactly like C's for compatibility reasons. foo.c #include <stdio.h> ...

Integer ASCII value to character in BASH using printf

Character to value works: $ printf "%d\n" \'A 65 $ I have two questions, the first one is most important: How do I take 65 and turn it into A? \'A converts an ASCII character to its value using printf. Is the syntax specific to printf or is it used anywhere else in BASH? (Such small strings are hard to Google for.) ...

Should I cast a CString passed to Format/printf (and varargs in general)?

I recently took in a small MCF C++ application, which is obviously in a working state. To get started I'm running PC-Lint over the code, and lint is complaining that CStringT's are being passed to Format. Opinion on the internet seems to be divided. Some say that CSting is designed to handle this use case without error, but others (an...

Oracle 'printf' equivalent

Is there an equivalent or alternative to the following? SELECT mix_type || ' (' || mix_num || ')' as description FROM acid_batch WHERE mix_num < 10 Does Oracle have something like printf style formatting? SELECT printf("%s (%s)", mix_type, mix_num) as description, FROM acid_batch WHERE mix_num < 10 ...