Possible Duplicate:
How to escape the % sign in Cs printf?
This has to be an easy question but I can't find the answer on my book or the web; how to print '%' in C ?
e.g.:
printf("A: %.2f%", pc);
...fails, the compiler complains there is an invalid conversion. Of course an easy way is;
printf("A: %.2f%c", pc, '%');
But ...
I have a vc++ method that uses fprintf to write values to a file in the hard disc. I want to change this method so that instead of writing the values to disc, I want to return a pointer to the data.
I know in advance the size I have to allocate. Is there any way to pass a memory stream or unsigned char pointer to fprintf?
thanks
...
I can never understand how to print unsigned long datatype in C.
Suppose boo is an unsigned long, then I try:
printf("%lu\n", unsigned_boo)
printf("%du\n", unsigned_boo)
printf("%ud\n", unsigned_boo)
printf("%ll\n", unsigned_boo)
printf("%ld\n", unsigned_boo)
printf("%dl\n", unsigned_boo)
And all of them print some kind of -12312312...
I know how to do X amount of leading zeros, and I know how to do X amount of decimal points. But, how do I do them both?
I am looking to have 4 leading zeros to a decimal precision of 2: 0000.00.
Therefore 43.4 would be 0043.40
...
Hi there,
I read about freopen to redirect all printf to a file, but I would like the output to be printed on the screen as well. Is there an easy way to redirect the printfs to a file and get the cmd line output?
Thanks!
...
I'm trying to format some printf statements to allow for arbitrary levels of indentation.
Ideally I want the following output where "One", "Two", etc are placeholders for variable length log messages.
One
Two
Three
Two
One
I'm working on the variable length spacing required for the indentation, and I know I can do the following:
...
What is the output of the following and what's the reason behind this?
main()
{
printf("%%%%");
}
The answer is "%%", but I don't know why.
...
I now want to know that means this line:
printf("Answer: %00010.6f", 22);
He prints: 022.000000. But way? i know whar 6f means float.
thansk for answers
...
Hi guys,
This a very simple c question.
Is there a way to format a float for printf so that it has xx SIGNIFICANT decimals?
So I'm not take about, say, %5.3 float, but if I had
float x=0.00001899383
how would i output 0.0000189 if i wanted UP TO the first three non-zero decimals?
thanks! I'm not stating at home this weekend so I do...
This script will read an old and a new value from the user and then use sed to find and replace them in a file. For example if I entered T*T*z and B*B*z it would look for T\*T\*z in the file and replace with B\*B\*z. It works but I've been trying to make this more concise.
I don't have any need for the intermediate variables $ESC_OL...
How is the following line interpreted by gcc Compiler:
printf("HELLO");
I want to know this because when I am running following program:
main()
{
printf(5+"Good Morning");
}
The program is printing
Morning
I understand that the compiler is starting the printing from the 5th index.
But Why?
...
Hi,
I have a pretty obscure problem here. I'm writing a photoshop plugin (for mac) using Xcode.
I use printf statements for simple debugging. A printf without a format string works fine, however, if I use a format string to try and print out a value it does not show up in xcode's debugger console.
#include <stdio.h>
DLLExport ...
I'm looking at a code line similar to:
sprintf(buffer,"%02d:%02d:%02d",hour,minute,second);
I think the symbolic strings refer to the number of numeric characters displayed per hour, minute etc - or something like that, I am not entirely certain.
Normally I can figure this sort of thing out but I have been unable to find any useful ...
#include<stdio.h>
main()
{
float x=2;
float y=4;
printf("\n%d\n%f",x/y,x/y);
printf("\n%f\n%d",x/y,x/y);
}
Output:
0
0.000000
0.500000
0
compiled with gcc 4.4.3
The program exited with error code 12
...
In eiffel how do you make it so that the number.
118.1999999999999
prints to:
118.20
In other language is simply a matter of printf but there seems no to be a way to do that easily in Eiffel.
...
What is the use of "%n" format specifier in C. Could anyone explain with an example.
Thanks in advance.
...
I've recently been writing some basic command-line programs (I want to keep my skills sharp over the summer), but printf and scanf have been starting to annoy me. I'm not a wonderful C programmer, and having to get into printf/scanf and their instabilities (or even worse, fgets and their ilk) isn't exactly putting me in a comforting sett...
When providing the wrong number of arguments to printf():
printf("%s", "foo", "bar");
or when by providing arguments of the wrong type:
printf("%d", "foo");
gcc is able to warn about these mistakes:
$ gcc -Wformat printf_too_many_arguments.c
printf_warnings.c: In function `main':
printf_warnings.c:5: warning: too many arguments fo...
Hi,
I'm trying to convert this C printf to C#
printf("%c%c",(x>>8)&0xff,x&0xff);
I've tried something like this:
int x = 65535;
char[] chars = new char[2];
chars[0] = (char)(x >> 8 & 0xFF);
chars[1] = (char)(x & 0xFF);
But I'm getting different results.
I need to write the result to a file
so I'm doing this:
tWriter.Write(chars)...
It's been awhile since I've played with c, and now I find something I've never seen before:
printf("%-16llu", my_var);
It would seem to be saying print 16 characters of a long unsigned int. But, what's the second 'l' for? long long?
...