printf

printf and formatting rules

I'd like to know if all formatting rules of printf functions currently work (or are implemented) in F# ? For instance, if I want to align arguments on 9 characters (padding with spaces or 0), I would use: printfn "%9A %9A" arg1 arg2 //don't seem to work Thanks! ...

warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’

I think this code and error is self-explanatory, but I don't know why? Environment: OS: Mac OS X 10.6.1 Compiler: i686-apple-darwin10-gcc-4.2.1 code: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <netdb.h> 4 #include <sys/socket.h> 5 6 int 7 main(int argc, char **argv) 8 { 9 char *ptr, **pptr; 1...

std::string.resize() and std::string.length()

I'm relatively new to C++ and I'm still getting to grips with the C++ Standard Library. To help transition from C, I want to format a std::string using printf-style formatters. I realise stringstream is a more type-safe approach, but I find myself finding printf-style much easier to read and deal with (at least, for the time being). This...

Reading a variable messes it up?!?!

We have the following line of code: printf("%d\n", toc->runlist.next); printf("%d\n", toc->runlist.next); These are the definitions: typedef struct thread_overview_control{ int id[NR_UTHREADS]; list_t runlist; int active_counter; int main_thread; int need_resched; } thread_overview_control; thread_overview_cont...

Is it possible to write a Java printf statement that prints the statement itself?

Is it possible to have a Java printf statement, whose output is the statement itself? Some snippet to illustrate: // attempt #1 public class Main { public static void main(String[] args) { System.out.printf("something"); } } This prints something. So the output of attempt #1 is not quite exactly the printf statement in attempt #1....

Is this an F# structured printf bug?

Code: printfn "%10s" "abc" printfn "%-10s" "abc" printfn "%10d" 123 printfn "%-10d" 123 printfn "%10c" 'a' printfn "%-10c" 'a' Output: abc abc 123 123 a a So right aligning %c does not work as I expect... F# 2.0 build 4.0.30319.1 ...

Are there any good descriptions of scientific notation formatting using printf

Please no general printf descriptions. ...

Help with my printf function

For debugging purposes I would like to have a printf_debug function that would function just like the standard printf function, but would only print if a #DEFINE DEBUG was true I know I have to use varagrs (...) but I have no idea how to actually achieve that. Thanks in advance. ...

will 'printf' always do its job?

printf("/*something else*/"); /*note that:without using \n in printf*/ I know printf() uses a buffer which prints whatever it contains when, in the line buffer, "\n" is seen by the buffer function. So when we forget to use "\n" in printf(), rarely, line buffer will not be emptied. Therefore, printf() wont do its job. Am I wrong? ...

Is this a correct syntax (c code found on wikipedia)?

I just found this code on wikipedia. Link: http://en.wikipedia.org/wiki/Sizeof#Use The code: /* the following code illustrates the use of sizeof * with variables and expressions (no parentheses needed), * and with type names (parentheses needed) */ char c; printf("%zu,%zu", sizeof c, sizeof(int)); It states that: "The z prefix ...

Printing values in special format using printf

I need to print the following values with printf as the follwoing around like this: printf "[`date +%d"/"%b"/"%G"-"%T`] [WARN] $PARAM1 $PARAM2 $PARAM3 The required output: [02/Jun/2010-11:08:42] [WARN] val1....val2...val3 the gap between val1 to val2 and from val2 to val3 must be const gap not depend the length of the values ...

printf, sprintf print at least two decimal places

I'm trying to figure out how to use sprintf to print at least two decimal places and no leading zeros. For instance input: 23 23.0 23.5 23.55 23.555 23.0000 output: 23.00 23.00 23.50 23.55 23.555 23.00 any formatting help would be appreciated ...

C: Segmentation Fault while using printf

Hello folks, This one is probably very simple, but I can't seem to get it working. I have this very simple snippet of code: #include <stdio.h> #include <string.h> int main(void) { char buf[100]; char *p = buf; strcpy(p, "Test string"); printf("%s\n", *p); } Which causes a segmentation fault when I run it. GDB outputs: ...

Java Formatter specify starting position for text

I'm trying to position a string at a certain starting position on a line, regardless of where the previous text ended. For instance: Mandatory arguments to long options are mandatory for short options too. -a, --all do not ignore entries starting with . -A, --almost-all do not list implied . and .. The e...

Whats the easiest way to convert a long in C to a char*?

What is the clean way to do that in C? wchar_t* ltostr(long value) { int size = string_size_of_long(value); wchar_t *wchar_copy = malloc(value * sizeof(wchar_t)); swprintf(wchar_copy, size, L"%li", self); return wchar_copy; } The solutions I came up so far are all rather ugly, especially allocate_properly_size_whar_t u...

How to print %s in C?

I want to print "%SomeString%" in C. Is this correct? printf("%%s%",SomeString); ...

How to get printf style compile-time warnings or errors

I would like to write a routine like printf, not functionally-wise, but rather I'd like the routine to have the same time compile check characteristics as printf. For example if i have: { int i; std::string s; printf("%d %d",i); printf("%d",s.c_str()); } The compiler complains like so: 1 cc1plus: warnings being treated a...

How to make printf() properly print a binary blob from within a macro?

In a project of mine (which for technical reasons must not depend on any external libraries or third-party sources) I have set up the following test.h: static int rc = 0; #define TESTCASE( x ) if ( x ) {} \ else \ { \ rc += 1; \ printf( "FAIL...

address of array ptr equal to to it's value ?

Possible Duplicate: C: How come an arrays address is equal to its value? SA In C I tried to print the address of the pointer of an array. int a[3] = {0,1,2}; printf("\n%p",a); printf("\n%p",(&a)); the 2 statement prints the same value why?thanks in advance ...

How to 'catch' c printf in python with ctypes?

Hi there, I hope this is trivial and I just didn't find it in the tutorials. I am writing python code that 'supervises' c code, aka I run the c code with ctypes from python. Now I want to 'catch' the c 'printfs' to process the data that is output by the c code. Any idea how one would do this? Thanks ...