printf

What's up with Java's "%n" in printf?

I'm reading Effective Java and it uses %n for the newline character everywhere. I have used \n rather successfully for newline in Java programs. Which is the 'correct' one? What's wrong with '\n' ? Why did Java change this C convention? ...

Roundtripping double to text and back

Using Cocoa or basic c, how can I convert a double to a string representation and then convert it back to the exact same double. Readability is not important, only accuracy. For example, will this work: double a,b; a=some value; b=[[[NSNumber numberWithDouble:a] stringValue] doubleValue]; ...

Problem with scanf in Eclipse / MiniGW

I'm trying to run the following code in eclipse but the console remains blank until i stop the program at which point the output "Enter next value (<=0 to quit)2130567168 minutes is 35509452 hours, 48 minutes." is repeated over and over. It seems that scanf is putting some default value in for some reason... can't figure out why. I'm no...

formatting the output using c

i have multiple outputs that i need to print as columns side by side. is there any way to achieve this using C? something like the output of ls -a i.e. i want to print the first column data, then the second and so on ...

problem in printing floating point

hi I am using IAR c compiler, I am trying to print floating point value like printf("version number: %f\n",1.4); but I am always getting like below in console version number:ERROR help please thanks in advance kudi ...

mixing cout and printf for faster output

After performing some tests I noticed that printf is much faster than cout. I know that it's implementation dependent, but on my Linux box printf is 8x faster. So my idea is to mix the two printing methods: I want to use cout for simple prints, and I plan to use printf for producing huge outputs (typically in a loop). I think it's safe t...

Why doesn't scanf need an ampersand for strings and also works fine in printf (in C)?

I am learning about strings in C now. How come to use scanf to get a string you can do scanf("%s",str1); and for printf you can do printf("The string is %s\n", str1); I understand that for scanf it is because the string is just a character array which is a pointer, but for printf, how is it that you can just put the variable name...

OnClick location Not Work

**this Line not work properly /r work but $siteurl/%s-%s.html not work i think problem of ("") or ('') please help me to repair it printf("<a href='/r?%s' target=_blank onClick='window.open(location.href=$siteurl/%s-%s.html)>", $wurl, $myrow["wallpaperid"], $myrow["wallpapername"]); ...

Call different functions using Direct Parameter Access in C

Hello, I recently stumbled upon this page. And I was particularly interested about the section which dealt with Direct Parameter Access. I was just wondering if there is any way to execute just one of the functions depending on the value of n in the following line: printf("%n$p", func1, func2, func3 .. funcN); where func1,.. have si...

how to help programmer write safe and correct printf calls in C?

[Updated organization and content for clarity] The Real Question What would be a good way, for C, to help a programmer, while s/he's typing, write safe and correct calls to project-specific printf-like debugging functions? C macros? C wrapper functions? Code editor macros or templates? Other? Background Questions and Answers Much so...

Is it possible to refresh two lines of text at once using something like a CR? (C++)

Right now, I have a console application I'm working on, which is supposed to display and update information to the console at a given interval. The problem I'm having is that with a carriage return, I can only update one line of text at a time. If I use a newline, the old line can no longer be updated using a carriage return. What can I...

What kind of strings does CFStringCreateWithFormat expects as arguments?

The below example should work with Unicode strings but it doesn't. CFStringRef aString = CFSTR("one"); // in real life this is an Unicode string CFStringRef formatString = CFSTR("This is %s example"); // also tried %S but without success CFStringRef resultString = CFStringCreateWithFormat(NULL, NULL, formatString, aString); // Here I...

what does the % % mean in java?

Im a PHP-programmer and wonder what this line means. System.out.printf("exp(%.3f) is %.3f%n", x, Math.exp(x)) what does %.3f, %.3f%n and the comma x means? ...

Is %dn a format string ?

Hi , I recently came across this line in a code - fprintf(logfile," |-IP Version : %dn",(unsigned int)iph->version); Is "%dn" here a format string ? If so , what does it signify ? ...

How to check that vsprintf has the correct number of arguments before running.

I'm trying to use vsprintf() to output a formatted string, but I need to validate that I have the correct number of arguments before running it to prevent "Too few arguments" errors. In essence I think what I need is a regex to count the number of type specifiers, but I'm pretty useless when it comes to regex and I couldn't fund it anyw...

What does this C warning mean? "int format, pointer arg"

#include <stdio.h> int main() { // Declarations int iCount1, iCount2; int iXXTest[4][3] = {{2, 3, 5}, {9, 8, 6}, {1, 8, 4}, {5, 9, 7}}; // Walk through 1st dimension for (iCount1 = 0; iCount1 < 4; iCount1++) { // Walk through 2nd dimension for (iCount2 = 0; iCount2 < 3; iCount2++) { print...

What value does a call to printf() produce?

In my programming class, I don't understand what the value of printf("World") is (question my prof is asking)? What value does a printf have? He says it is 5, but I don't know why. Thanks. ...

Inserting spaces between digits in C

How would I go about taking a number like 123456 and having it print as 1 2 3 4 5 6? ...

How to use Java or Groovy printf to add Thousands separator to String

In Java, I need to add a thousands separator to a decimal number formatted as a String. However, I do not want a millions or billions separator... just a thousands separator with the existing fractional part of the number preserved. 9 == 9 999.999 == 999.999 9,999 == 9999 999999,999.999 == 999999999.999 I do not strictly need to us...

How can I prevent Perl from interpreting \ as an escape character?

How can I print a address string without making Perl take the slashes as escape characters? I don't want to alter the string by adding more escape characters also. ...