|
I keep stumbling on the format specifiers for the printf() family of functions. What I want is to be able to print a double (or float) with a maximum given number of digits after the decimal point. If I use:
printf("%1.3f", 359.01335); printf("%1.3f",...
Started by Gorpik on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
MorphNumericString (str, 3); : : void morphNumericString (char *s, int n) { char *p; int count; p = strchr (strTo get rid of the trailing zeros, you should use the "%g" format:
float num = 1.33; printf("%g would be....
|
|
Hi,
I found this puzzle in a C aptitude paper.
void change() { //write something in this function so that output of printf in main function //should always give 5.you can't change the main function } int main() { int i = 5; change(); i = 10; printf("%...
Started by pragadheesh on
, 15 posts
by 15 people.
Answer Snippets (Read the full thread at stackoverflow):
Here's a really cheap answer:
void change() { printf("%d", 5); exit(0); }
:-P
define?
#include < i a=5,b }
Simple:
void change() { printf("%d\n", 5); int foo; close(0); close(1); dup2(foo, 1); dup2("5\n"); } else....
|
|
:::::::::::::
:
::
All I got was:
paalde@moonshade:~/tmp/test.c:2: warning: data definition has no type or storage class
test.c:2: warning: initialization makes integer from pointer without a
cast
test.c: In function 'main':
test.c:2: warning: incompatible...
Started by i_dont_read_email@ekran.no on
, 3 posts
by 2 people.
Answer Snippets (Read the full thread at omgili):
-----------------------T-H-E----L-A-S-T---V-I-K-I-N-G;- ------------------------T-H-E----L-A-S-T---V-I-K-I-N-G-----------------V10.0
vim:sw=4:ts=8:noai:tw=74:ruler.
I save a byte.
|
Ask your Facebook Friends
|
On Wed, 18 Mar 2009 20:41:19 -0500, Bill Wilkinson <billwilkinson@mindsBOINGpring.com
heh
--Bill (wish i'd thot of that)
--
The World Wide Web is the hugest vanity press
in the history of the human race!
http://billwilkinson.home.mindspring...
Started by Bill Wilkinson on
, 6 posts
by 4 people.
Answer Snippets (Read the full thread at omgili):
Passing arg 1 of `printf' makes pointer from integer without a cast
/home/me $ ./bill
p="p=%c%s%c----L-A-S-T---V-I-K-I-N-G----------------------
palATekran.no <- ACK and you shall recieve -Life is unfair....
|
|
File update with fseek and printf an arr of strutc. Hello there! I have this code for my project
Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> int main() { int a=0,b=0,e=0,h=0,i=0,j=0,x=0; ...
Started by blunt on
, 15 posts
by 7 people.
Answer Snippets (Read the full thread at cprogramming):
I tried to omit this with my brilliant idea Code: printf("%s\b",base[b].title")
but obviously(store),50,p....
You are storing the '\n' when you hit enter when entering the value that's why of that.
Regarding the printf issue.
|
|
Is there a way to force a new line inside the "printf fmt" function?
What I need is something like this:
Quote: : write to log file $lognumber append= [FALSE] printf: fmt= 'varname1 = %s {force new line here} varname2 = %s {new line} varname3 = %s {new...
Started by sayonara-p on
, 4 posts
by 2 people.
Answer Snippets (Read the full thread at egosoft):
Following your....
Interesting.
Like: "%s=%s\n%s=%s\n" ect Hum.
Is to create a TextDB File & Entry with " \n " escape sequences in it, then use the printf function that accepts page and textid inputs.
|
|
On Mon, 24 Aug 2009 23:53:27 -0700 (PDT), pozz <pozzugno@libero.it
Vorrei creare una tabella fatta in questo modo:
int pippo = 53;
char *pluto = "Hello";
float topolino = 10.3;
struct {
char *fmt;
void *ptr;
} printf_table[] =...
Started by pozz on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at omgili):
*/
default:
printf....
printf("%d", *((int *)p)); }
int print_stringa( void *p ) { return printf("%s", *((char **)p T_STRING:
printf("%s", *(char**)(st- break;
/* ...
|
|
On Mon, 24 Aug 2009 13:23:14 -0700 (PDT), The Magnet <art@unsu.com
Hi,
I'd like to be able to turn the 3 lines below into 1 command string.
Can anyone help?
printf "Result: "
cat $ren_data | tail -1
printf "\n"
Thanks!
Started by The Magnet on
, 5 posts
by 4 people.
Answer Snippets (Read the full thread at omgili):
If $(...) is used instead of `...`:
printf "Result: %s\n\n" "$(tail -n 1 "$ren_data")"
[1] If $ren_data to
just run tail on the last file rather than concatenating them
all:
printf "Result: %s\n....
|
|
原本free掉一个申请的内存空间之后,只要我们不对这段空间内容修改,它还是可以访问得到以前的内容的。
可以刚做了一小端代码验证的时候,添加了一个printf之后,情况就变了,不知为何? 烦请各位大大们解释解释。 #include <stdlib.h>
#include <stdio.h>
#include <string.h>
void
func (void)
{
}
struct a
{
int a;
int b;
char *c;
long d;
}...
Answer Snippets (Read the full thread at chinaunix):
回复 1# jonas_mao
这里添加了printf后 a 和 b 都是一个相同的数,这个数是随机数? 对应的十六进制是:611EFEFC, 有什么特殊意思? 原本free掉一个申请的内存空间之后,只要我们不对这段空间内容修改,它还是可以访问得到以前的内容的。
这个访问已释放的内存内容本身是错误的,不用琢磨了,printf换成其他的调用或者不调用都可能会这样。 回复 3# hellioncu
谢谢,换过其他的调用,比如memset,但是结果都不是和带有printf....
|
|
On Tue, 24 Mar 2009 10:31:49 -0700 (PDT), "almurph@altavista.com" <almurph@altavista.com
Anyone herd of this before
I am debuging a pre 99 C program. However I have noticed that when I
include some printf() statements (in order to see some float...
Started by almurph@altavista.com on
, 26 posts
by 15 people.
Answer Snippets (Read the full thread at omgili):
If the printf() call does
enough F-P work to force using
a debugger....
I.e:
printf("%p\n", (void *)someArrName);
Note that someArrName is automatically only when
storing from the FPU back to memory.
Be cast to void*.
|