作者MoseHas (非主流摩斯) (′‧ω‧‵)
看板TFSHS68th321
標題Re: [發問] 關於C
時間Fri Apr 10 12:53:29 2009
因為我很弱
所以我也不太記得
不過印象中fprintf跟fscanf是開檔讀檔用的
(翻課本找格式中)
我打上我們課本上的範例(賺P=3=)
#include <stdio.h>
int main(
void)
{
int account;
//account number
char name[
30];
//account name
double balance;
//account balance
FILE *cfPtr;
//cfPtr = clients.dat file pointer
//fopen opens file. Exit program if unable to create file
if (cfPtr=fopen("clients.dat","w")==NULL)
printf("File could not be opened\n");
//編按:fopen => open a file, "w" represents type "write"
//u can use "r" to represent read
else
{
printf("Enter the account name, and balance.\n");
printf("Enter EOF to end input.\n");
printf("? ");
scanf("%d%s%lf",&account,name,&balance);
//編按:scanf format: &account, &balance to find its memory address
//I rarely use %s to get a string, so i cannot understand why here is name
//instead of &name...
//write account, name and balance into file with fprintf
while(!feof(stdin))
{
fprintf(cfPtr, "%s %s %.2f\n", account,name,balance);
printf("? ");
scanf("%d%s%lf",&account,name,&balance);
}
fclose(cfPtr);
//fclose closes file
//編按:After any file reading or writing, please remember to fclose this file
}
return 0;
}
要用C格式,請注意pointer的觀念...
scanf到的東西,要丟進去一個變數,必須先取她的address
大致上是這樣...
其實你也已經問到滿深了
有更深入的問題可以去C/C++板問
我很弱我只會嘴砲
怎麼不去找菌絲?
他應該念的不錯吧=3=
--
◢▅▇◣▉ ◣
﹨ ∥∥ ∕
▉ ◥ ▊★
◣▂
▊ ◢◤ ◥▇▆▅▆▇◤
╲◢‥‥◥╱
◥◣
◤ ▊▊▊ ◥
▍◢◤▉▅◣◢▆◣ ▊
══'╴‥╴'══Craig
◢
◥◣ ▋▋
▇◤
▌◣ ▊ ▉ ▊ ▉ ▋
══' / '══
◣
█ ▋▍▋
▎ ◥◣
◥▌◥▆◤ ▋
══'﹏﹏﹏'══
◥
▂◤ ◤◤▌
◥ ◥
◥ ◥ ◢◣ ◢◣ ψcafelife
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.227.186.249
推 crazyma:看我幫你賺多少P幣XDD 感謝專業的摩斯大<(_ _)> 04/10 14:39
→ crazyma:菌絲boy只會對我比中指 ...凸 04/10 14:39
推 kfc1805:怎麼出現學術的氣息了 馬儒真是一股清流 嘖嘖 04/10 14:40
推 crazyma:樓上翹課>0<@m 04/10 14:42
推 justforfree:那我可以上來班版問會計嗎? 04/10 19:28
→ MoseHas:我可不會會計啊 04/11 01:45