printf

printf() functionality in Java combined with a CharBuffer or something like it

I am a little confused here. I would like to do something like this: create some kind of buffer I can write into clear the buffer use a printf()-like function several times to append a bunch of stuff into the buffer based on some complicated calculations I only want to do once use the contents of the buffer and print it to several Pri...

Behaviour of printf when printing a %d without supplying variable name.

I've just encountered a weird problem, I'm trying to printf an integer variable, but I forgot to specify the variable name, i.e. printf("%d"); instead of printf("%d", integerName); Surprisingly the program compiles, there is output and it is not random. In fact, it happens to be the very integer I wanted to print in the first place, ...

How to print out dash or dot using fprintf/printf?

As of now I'm using below line to print with out dot's fprintf( stdout, "%-40s[%d]", tag, data); I'm expecting the output would be something like following, Number of cards..................................[500] Fixed prize amount [in whole dollars]............[10] Is this a high winner prize?.....................[yes] How to prin...

How will you print a character without library functions in C ?

If for example I should not use standard library functions like printf, putchar then how can I print a character to the screen easily. Is there any easy way of doing it. I dont know much about system calls and if I have to use them then how? So can any one advice an easy way of printing a character without using library functions?? Than...

Print void type in pure C

i have a function like void printMe (void *i) { printf("%d", i); } where i want to pass a void pointer and print it to screen. The above example is fine if the i is integer, float or double but crashes if i is a char. There is no overloading in C like i usually use in C++. So the question is this, can we create a function in C tha...

How to *printf* in Python?

The question is in the title. I'd like to do in Python what I do in this example in C: #include <stdio.h> int main() { int i; for (i=0; i<10; i++) printf("."); return 0; } Output: .......... In Python: >>> for i in xrange(0,10): print '.' . . . . . . . . . . >>> for i in xrange(0,10): print '.', . . . . . . . . . . ...

create a my_printf that sends data to both a sprintf and the normal printf?

Hi I am playing with the printf and the idea to write a my_printf(...) that calls the normal printf and a sprintf that sends the result to a special function. (I was thinking about sprintf since that behaves just like printf on most platforms). My idea was to write a small macro that did this: #define my_printf(X, Y...) do{ printf...

Problem redirecting a C program output in bash

I've coded a program in C that sends messages to the stdout using printf and I'm having trouble redirecting the output to a file (running from bash). I've tried: ./program argument >> program.out ./program argument > program.out ./program >> program.out argument ./program > program.out argument In each case, the file program.out is...

Printf formatting

Hey all. I want to use print to print hex numbers in the form 0x###, but if the number is 0, I want to omit the 0x part. How can I do this? Thanks! ...

Segfault when using printf

I am debugging some Linux C code in a signal handler for floating point exceptions. The goal is to check the floating point registers, print some information, and then abort. I get a segmentation fault when attempting to printf the result of (char)('0' + phyreg). struct ucontext * uc = (struct ucontext *) data; fpregset_t fp = uc ...

How can I render undefined values from printf in Perl?

I'm looking for an elegant way to denote undefined values in situations where formatted numbers usually render. I'll work up a small example. For starters, you of course can't use this: #!/usr/bin/perl use strict; use warnings; for my $s (1, 1.2, undef, 1.3) { printf "%5.2f\n", $s; } ...because the 'use warnings' nails you with 'U...

Is there a good reason to use "printf" instead of "print" in java?

I haven't had the chance to take any serious low-level programming courses in school. (I know I really should get going on learning the "behind-the-scenes" to be a better programmer.) I appreciate the conveniences of Java, including the ability to stick anything into a System.out.print statement. However, is there any reason why you woul...

error with printf statement? (In C) *Update*

For clarification purposes I need the program to print the numbers that are input for a and b, not the actual letters a and b. Okay here's the revised program per yall's suggestions: int main (int argc, char *argv[]) { int a; /*first number input*/ int b; /*second number input*/ a = atoi(argv[1]); /*assign to a*/ ...

Why does "%.3i" print leading zeros?

There was a bit of a surprise with some code today. I was compiling it on AIX, with the warning level set to anal to see what rogue issues might be lurking. Something new crawled out of the code. 1540-2837 (W) '0' flag is disregarded when combined with precision and 'i' printf format. After looking at the offending...

In Perl, how can I limit the number of places after the decimal point but have no trailing zeroes?

This question is similar to "dropping trailing ‘.0’ from floats", but for Perl and with a maximum number of digits after the decimal. I'm looking for a way to convert numbers to string format, dropping any redundant '0', including not just right after the decimal. And still with a maximum number of digital, e.g. 3 The input data is fl...

how to print a string vertically in c?

Ok the output is supposed to look like this: ./a 3 4 8 2 3 4 8 2 This is what I have so far, but I am lost and can only get the first integer to print (we have to use GetInt, which gets the specified integer in the string): int main (int argc, char*argv []){ int v; int i; i = 1; v = GetInt(argc, argv...

Qualifiers for printf on WinCE

On WinCE, when using printf, what are the qualifiers for various data types - short, unsigned long etc. For short and ulong, I know the answers are %hd & %lu, I am actually looking for a MSDN site that lists all data types and their qualifiers on CE. Unfortunately I cannot find the site now. I have already looked at this post, but it d...

why does printf show a 0 for vector size when cout shows the correct size?

I don't get why I get 0 when I use printf and %d to get the size of my vector: vector<long long> sieve; int size; ... //add stuff to vector ... size = sieve.size(); printf("printf sieve size: %d \n", size); //prints "printf sieve size: 0" std::cout << "cout sieve size: "; std::cout << size; std::cout << " \n "; //prints "cout sieve size...

Javascript printf/string.format

I'm looking for a good Javascript equivalent of the C/PHP printf() or for C#/Java programmers, String.Format() (IFormatProvider for .NET). My basic requirement is thousand seperator format for numbers for now, but something that handles lots of combinations (including dates) would be good. I realise Microsoft's AJAX library provides a ...

snprintf Format String security vulnerability issue

We have a Coverity bug for this line of code: snprintf( tempStr, size, testStrings[testID], A2DtoV(testResults[testID].value), A2DtoV(testResults[testID].min),A2DtoV(testResults[testID].max)); The error says: non_const_printf_format_string: "format string is not a string literal, potential security vulnerability if user controlled" ...