printf

difference betweent printf and gets

Hi, I am beginner for programming.I referred books of C programming,but i am confused. 1.) What's the difference betweent printf and gets? I believe gets is simpler and doesn't have any formats? ...

Printf with Double Formatting Question

I've got the following printf statement: printf("val=%-4.2lf", val); However, val is never padded with spaces so the space taken up by val is different if there are 3 or 4 digits before the decimal. Shouldn't the 4 in the format specifier guarantee that there are at least 4 spaces? Sorry for the newb question but it's been frustratin...

Trouble with printf in Bison Rule

I have tried something like this in my Bison file... ReturnS: RETURN expression {printf(";")} ...but the semicolon gets printed AFTER the next token, past this rule, instead of right after the expression. This rule was made as we're required to convert the input file to a c-like form and the original language doesn't require a semicol...

Why does printf not print out just one byte when printing hex?

pixel_data is a vector of char. When I do printf(" 0x%1x ", pixel_data[0] ) I'm expecting to see 0xf5. But I get 0xfffffff5 as though I was printing out a 4 byte integer instead of 1 byte. Why is this? I have given printf a char to print out - it's only 1 byte, so why is printf printing 4? NB. the printf implementation is wrapped up...

How to tell printf() to get the value from the untyped (or byte-sequence) buffer

I have a buffer of raw values, say, void* buffer or better, char* buffer - a raw byte stream, for example, read from a file. I'd like the bytes in the buffer to be represented and displayed in several ways, for example, as a float, or as a long long in runtime. I'd ask a user for desired format string, for example, %10d, and pass the for...

how to printf a loop result?

How to printf results from a loop? For example if i have this something simple like this: k[0]=2; k[1]=3; k[2]=4; for (i = 0 ; i <= 2 ; i++) { x[i]=5*k[i]; } How do I print out the results for x[0],x[1],x[2] without having to keep repeating the array in printf? As in printf("%d %d %d\n",x[0],x[1],x[2]); I dont really want ...

Precision specifier as parameter like printf but in String.Format

Using printf i could specify the precision value as an extra parameter using *. Does the same functionality exist in the C# String.Format? edit: For example: Console.WriteLine("{0:D*}",1,4); // Outputs 0001; ...

Passing too many arguments to printf

Any C programmer who's been working for more than a week has encountered crashes that result from calling printf with more format specifiers than actual arguments, e.g.: printf("Gonna %s and %s, %s!", "crash", "burn"); However, are there any similar bad things that can happen when you pass too many arguments to printf? printf("Gonna ...

Print a leading '+' for positive numbers in printf

I've a temperature conversion program as an assignment, which I've completed. The program has many printf statements in it which print the temperature. Now the negative temperatures are printed the way I want them but the positive temperatures are printed without a leading + sign. Now what is the best way to get printf print a leading ...

AWK output formatting and syntax.

Hello everyone, Ive been trying to sort out output using AWK, and have been pretty successful going through some of the stuff on stack overflow until i hit the last part of the command below. -bash-3.2$ find /home/username/www/devdir -mindepth 2 -maxdepth 2 -type d -printf "%TY %Tm %Tb %Td,%TH:%TM,%p,\n" | grep "^$r" | grep Aug | sort -...

Clojure sprintf?

There is printf. It prints directly to stdout. How about sprintf, which formats the same way as printf, but returns a string with no side-effects? ...

sprintf fails spontaneously depending on what printf and NSLog calls there are.

Hello I have a bizarre problem with sprintf. Here's my code: void draw_number(int number,int height,int xpos,int ypos){ char string_buffer[5]; //5000 is the maximum score, hence 4 characters plus null character equals 5 printf("Number - %i\n",number); sprintf(string_buffer,"%i",number); //Get string printf("String - %s\n...

c++ - printf on strings prints gibberish

Hi, Sorry about the simple question - I'm a newby (obviously): I'm trying to print a string the following way: int main(){ string s("bla"); printf("%s \n", s); ....... }; but all I get is this random gibberish. Can you please explain why? Thanks, Li ...

Explain C code snippet: preprocessor + printf = ???

The output for this code snippet is %s is a string is a string. Please explain. #include <stdio.h> #define scanf "%s is a string" int main() { printf(scanf, scanf); } ...

which is faster, and which is more flexible: printf or cout?

Possible Duplicates: printf vs cout in C++ cin or printf?? I've always wondered about printf and cout.. which one is ultimately faster, and is it the most flexible as well (ie can print a range of variables, and output can be formatted)? P.S. I know this looks similar to http://stackoverflow.com/questions/2872543/printf-vs-...

How to display hexadecimal numbers in C?

I have a list of numbers as below: 0, 16, 32, 48 ... I need to output those numbers in hexadecimal as: 0000,0010,0020,0030,0040 ... I have tried solution such as: printf("%.4x",a); // where a is an integer but the result that I got is: 0000, 0001, 0002, 0003, 0004 ... I think I'm close there. Can anybody help as I'm ...

printf weird issue with two unsigned long int

hi. i have this code (im working with big files support in ansi c) unsigned long int tmp,final final=1231123123123213 tmp=final; printf("%llu %llu \n",final,tmp); printf("%llu \n ",tmp); it prints 1231123123123213 0 1231123123123213 i dont get it ...

printf prints the wrong values

Why do I get the wrong values when I print a int using printf("%f, myNumber) ? I don't understand why it prints fine with %d, but not with %f. Shouldn't it just add extra zeros? int a = 1; int b = 10; int c = 100; int d = 1000; int e = 10000; printf("%d %d %d %d %d\n", a, b, c, d, e); //prints fine printf("%f %f %f %f %f\n", a, b, c...

Escaping "white space" escaping in C

I'm it really sure how to explain this question but i'll give it a try. I have this line of code in my program: scanf (" %c", &character); Notice the space before %c. This is supposed to keep the scanf from interpreting the last ENTER key as a character. This works, however after this line and its resulting printf output the program w...

How to print hex value of 255 in Unix ?

Hi, can you please tell me How to use printf to find out the hex and octal values of 255? Thanks a lot. ...