線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1237
推到 Plurk!
推到 Facebook!

新手問題 txt值

答題得分者是:christie
egghead253
一般會員


發表:25
回覆:13
積分:7
註冊:2009-05-01

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-11-03 22:33:09 IP:219.85.xxx.xxx 訂閱
請問 我有一個值-1.5存入txt裡怎會變0


[code cpp]
outf=fopen("T1.TXT","w");
fprintf(outf,"%d ",-1.5);
fprintf(outf,"\n");

fclose(outf);
[/code]

christie
資深會員


發表:30
回覆:299
積分:475
註冊:2005-03-25

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-11-04 08:22:00 IP:59.125.xxx.xxx 訂閱
printf("%.1f\n",-1.5);


另外請參考HELP:

#include
#include

#define I 555
#define R 5.5

int main(void)
{
int i,j,k,l;
char buf[7];
char *prefix = buf;
char tp[20];

printf("prefix 6d 6o 8x 10.2e "
"10.2f\n");
strcpy(prefix,"%");
for (i = 0; i < 2; i )
{
for (j = 0; j < 2; j )
for (k = 0; k < 2; k )
for (l = 0; l < 2; l )
{
if (i==0) strcat(prefix,"-");
if (j==0) strcat(prefix," ");
if (k==0) strcat(prefix,"#");
if (l==0) strcat(prefix,"0");
printf("%5s |",prefix);
strcpy(tp,prefix);
strcat(tp,"6d |");
printf(tp,I);
strcpy(tp,"");
strcpy(tp,prefix);
strcat(tp,"6o |");
printf(tp,I);
strcpy(tp,"");
strcpy(tp,prefix);
strcat(tp,"8x |");
printf(tp,I);
strcpy(tp,"");
strcpy(tp,prefix);
strcat(tp,"10.2e |");
printf(tp,R);
strcpy(tp,prefix);
strcat(tp,"10.2f |");
printf(tp,R);
printf(" \n");
strcpy(prefix,"%");
}
}
return 0;
}

===================引 用 egghead253 文 章===================

請問 我有一個值-1.5存入txt裡怎會變0


[code cpp]
outf=fopen("T1.TXT","w");
?fprintf(outf,"%d ",-1.5);
?fprintf(outf,"\n");

?fclose(outf);
[/code]
?
------
What do we live for if not to make life less difficult for each other?
egghead253
一般會員


發表:25
回覆:13
積分:7
註冊:2009-05-01

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-11-10 02:15:24 IP:219.85.xxx.xxx 訂閱
謝謝前輩的指導!
我終於了解輸出的格式....
系統時間:2024-04-18 16:19:09
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!