#include <stdio.h>
int main(void)
{
double resd = 0.000116;
long long resi = 0;
printf("%lld %f %lld %f\n", resd, resd, resi, resi);
return 0;
}
gives (Linux, gcc, x64)
0 0.000116 0 0.000116
^^^^^^^^ odd, since the memory for resi is zeroed
Actually, compiled with g++ it gives random r...
Hello, I am having a confusing issue -- for me at least, this may be very simple and I am missing something. I am trying to initialize a 2D array of variable size, The array is a part of a struct. I am having no issue allocating memory for the array but when I try to assign characters to the array, or print them I receive unexpected resu...
I am new to programming so I apologize beforehand. I am running a program and am having a problem with the System.out.printf method in Java. I know everything else in the program is working correctly (tested it). However this does not seem to work.
The error is:
Exception in thread "main" java.util.IllegalFormatConversionException:...
Here is my short assembly program:
; This code has been generated by the 7Basic
; compiler <http://launchpad.net/7basic>
extern printf
; Initialized data
SECTION .data
f_0 dd 5.5
printf_f: db "%f",10,0
SECTION .text
; Code
global main
main:
push ebp
mov ebp,esp
push dword [f_0]
push printf_f
call printf
add esp,8...
I have noticed that a large number of C compilers issue warnings when the conversion specifiers in the format string of the printf/sprintf functions do not match the type or the count of the corresponding arguments.
That seems to me like a conceptual break since C doesn't have built-in functions according to the language specification.
...
I've always used printf, and I've never used write/format. Is there any way to reproduce printf("%12.5e", $num) using a format? I'm having trouble digesting the perlform documentation, but I don't see a straightforward way of doing this.
EDIT: based on the answers I got, I'm just gonna keep on using printf.
...
I discovered this while using ruby printf, but it also applies to C's printf.
If you include ANSI colour escape codes in an output string, it messes up the alignment.
Ruby:
ruby-1.9.2-head > printf "%20s\n%20s\n", "\033[32mGreen\033[0m", "Green"
Green # 6 spaces to the left of this one
Green # correctly ...
Edited to correct the question
I'm using awk to urldecode some text.
If I code the string into the printf statement like so: printf "%s", "\x3D" it correctly outputs =. The same if I have the whole escaped string as a variable.
However, if I only have the 3D, how can I append the \x so printf will print the = and not \x3D.
I'm using ...
int main(void) {
char *input;
printf("prompt>");
scanf("%s", input);
printf("%s", input);
return 0;
}
prompt>input
RUN FAILED (exit value 138, total time: 3s)
What's wrong with the code? Has to be either the scanf() or the second printf(). The input is of unknown length. A lot people have said to simply create a c...
Suppose you have a string which is NOT null terminated and you know its exact size, so how can you print that string with printf in C? I recall such method but I can not find out know...
...
I need to use something like NSLog but without the timestamp and newline character, so I'm using printf. How can I use this with NSString?
...
#include <stdio.h>
int main(void){
char x [] = "hello world.";
printf("%s \n", &x[0]);
return 0;
}
The above code prints out "hello world."
How would i print out just "h"? Shouldn't the access x[0] ensure this?
...
I am currently trying to print a message from a child process after calling execlp() within the child. However, nothing appears on the terminal after the call to execlp(). What causes my printf() calls to not display anything, and how can this be resolved?
...
Hi all,
I have a program in C that print a table. I want update the values of this table without reprint the entire table. I can update one line with \r character, but how I can update more than one line?
...
i.e. can printf be told to ignore zero when it precedes the decimal point?
...
I need to do some arithmetic with large hexadecimal numbers below, but when I try to output I'm getting overflow error messages "Hexadecimal number > 0xffffffff non-portable", messages about not portable, or the maximum 32bit hex value FFFFFFFF. All of which imply that the standard language and output routines only cope with 32 bit value...
I have a little (big, dumb?) question about int and chars in C. I rememeber from my studies that "chars are little integers and viceversa," and that's okay to me. If I need to use small numbers, the best way is to use a char type.
But in a code like this:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int ...
Possible Duplicate:
Confusion about the output..
#include<stdio.h>
void main()
{
int i=1,j=-1;
if(printf("%d",i)<printf("%d",j))
printf("%d",i);
else
printf("%d",j);
}
here in this program what is the output & how ?
...
_
#include<stdio.h>
int main()
{
int a=5,b=10;
printf("%d %d");
return 0;
}
...
Possible Duplicate:
what will be the output & why
#include<stdio.h>
int main()
{
int a=5,b=10;
printf("%d %d %d %d %d %d");
return 0;
}
output: 10 5 0 344 0 0
...