printf

How do you print a limited number of characters?

Sorry to put a post up about something so simple, but I don't see what I'm doing wrong here. char data[1024]; DWORD numRead; ReadFile(handle, data, 1024, &numRead, NULL); if (numRead > 0) printf(data, "%.5s"); My intention with the above is to read data from a file, and then only print out 5 characters. However, it prints out al...

How can I line up columns with Perl's printf when the value might be a number or a string?

I am trying to output a document that looks like this (more at http://pastebin.com/dpBAY8Sb): 10.1.1.1 100 <unknown> <unknown> <unknown> <unknown> <unknown> 72.12.148.186 94 Canada Hamilton ON 43.250000 -79.833300 0.00 ...

Can printf change its parameters??

EDIT: complete code with main is here http://codepad.org/79aLzj2H and once again this is were the weird behavious is happening for (i = 0; i<tab_size; i++) { //CORRECT OUTPUT printf("%s\n", tableau[i].capitale); printf("%s\n", tableau[i].pays); printf("%s\n", tableau[i].commentaire); //WRONG OUTPUT //printf("%s --- %s --- %...

How to get a substring in awk

This is one line of the input file: FOO BAR 0.40 0.20 0.40 0.50 0.60 0.80 0.50 0.50 0.50 -43.00 100010101101110101000111010 And an awk command that checks a certain position if it's a "1" or "0" at column 13 Something like: awk -v values="${values}" '{if (substr($13,1,1)==1) printf values,$1,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13}' fo...

Why my print current date time (C language) gives different answer

I want to get the current date (day, mon and year). I found out there are some functions in C to do that like ctime (get the string of time), localtime and gmtime. I tried with following code but the output are different. I get this output: The date and time is Tue Apr 20 2010 (which is correct) The year is : 110 The year is : 110. D...

Printf example in bash does not create a newline

Working with printf in a bash script, adding no spaces after "\n" does not create a newline, whereas adding a space creates a newline, e. g.: No space after "\n" NewLine=`printf "\n"` echo -e "Firstline${NewLine}Lastline" Result: FirstlineLastline Space after "\n " NewLine=`printf "\n "` echo -e "Firstline${NewLine}Lastline" R...

Printing a string and variable in MIPS

Here's the C representation of what I'm trying to do in MIPS assembly: printf ("x=%d\n", x); I know that I can do a syscall to easily print x= and I can also do a syscall to print the int x (which is stored in a register). However, that prints them like this (let's say x is 5): x= 5 How can I make them print on the same l...

PHP - print content from file after manipulation

Hello there, I'm struggling trying to read a php file inside a php and do some manipulation..after that have the content as a string, but when I try to output that with echo or print all the php tags are literally included on the file. so here is my code: function compilePage($page,$path){ $contents = array(); $menu = getMenuFor(...

How to center string output using printf() and variable width? [java]

I'm creating an output in Java using printf() to create table headers. One of the columns needs variable width. Basically it should look like this: //two coords Trial Column Heading 1 (20,30)(30,20) //three coords Trial Column Heading 1 (20,40)(50,10)(90,30) I tried to use: int spacing = numCoords * 7; /...

No speed-up with useless printf's using OpenMP

I just wrote my first OpenMP program that parallelizes a simple for loop. I ran the code on my dual core machine and saw some speed up when going from 1 thread to 2 threads. However, I ran the same code on a school linux server and saw no speed-up. After trying different things, I finally realized that removing some useless printf statem...

How do I use multiple precisions in printf()?

Looking at the information under the heading "Precision can be omitted or be any of:". The example: printf("%.*s", 3, "abcdef"); works, outputting:abc (truncating the rest of the string.) Now, I would like to have a string with multiple parameters formatted (truncated): printf("%.*s, %.*s", 3, 3, "abcdef", "xyz123"); but the progra...

When does printf("%s", char*) stop printing?

In my class we are writing our own copy of C's malloc() function. To test my code (which can currently allocate space fine) I was using: char* ptr = my_malloc(6*sizeof(char)); memcpy(ptr, "Hello\n", 6*sizeof(char)); printf("%s", ptr); The output would typically be this: Hello Unprintable character Some debugging figured that my co...

in c printf() returns what

in c printf() returns what? ...

Using stdint.h and ANSI printf?

Hi, I'm writing a bignum library, and I want to use efficient data types to represent the digits. Particularly integer for the digit, and long (if strictly double the size of the integer) for intermediate representations when adding and multiplying. I will be using some C99 functionality, but trying to conform to ANSI C. Currently I h...

How to combine two 32-bit integers into one 64-bit integer?

I have a count register, which is made up of two 32-bit unsigned integers, one for the higher 32 bits of the value (most significant word), and other for the lower 32 bits of the value (least significant word). What is the best way in C to combine these two 32-bit unsigned integers and then display as a large number? In specific: leas...

What does "%.6d" mean in printf

What does %.6d mean in: printf("%s.%.6d len:%d ", timestr, header->ts.tv_usec, header->len); Is it a typo? It seems %.6d is the same as %6d. ...

What primitive data type is time_t?

I do not know the data type of time_t. Is it a float double or something else? Because if I want to display it I need the tag that corresponds with it for printf. I can handle the rest from there for displaying time_t but I need to know the data type that corresponds with it. ...

printf("... %c ...",'\0') and family - what will happen?

How will various functions that take printf format string behave upon encountering the %c format given value of \0/NULL? How should they behave? Is it safe? Is it defined? Is it compiler-specific? e.g. sprintf() - will it crop the result string at the NULL? What length will it return? Will printf() output the whole format string or ju...

What does "%3d" mean in a printf statement?

In this code what is the role of the symbol "%3d"? I know that % means refer to a variable. This is the code: #include <stdio.h> int main(void) { int t, i, num[3][4]; for(t=0; t<3; ++t) for(i=0; i<4; ++i) num[t][i] = (t*4)+i+1; /* now print them out */ for(t=0; t<3; ++t) { for(i=0; i<4; ++i) ...

Why unsigned int contained negative number

Hi All, I am new to C, What I know about unsigned numerics (unsigned short, int and longs), that It contains positive numbers only, but the following simple program successfully assigned a negative number to an unsigned int: 1 /* 2 * ===================================================================================== 3 * 4 *...