作者rareone (拍玄)
看板C_and_CPP
標題[問題] C file processing的檔案到底存在哪裡
時間Mon Jan 4 06:37:49 2016
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
OS X
Xcode
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
只有stdio.h
問題(Question):
使用資料存取的檔案時,找不到檔案到底存在哪
餵入的資料(Input):
none
預期的正確結果(Expected Output):
恩...是生出一個叫oldname.txt的檔案吧
錯誤結果(Wrong Output):
找不到檔案
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
int main(void)
{
unsigned int account;
char name[30];
double balance;
FILE *cfPtr;
if ((cfPtr = fopen("oldname.txt", "w"))==NULL) {
puts("File could not be opened");
}
else {
puts("Enter the account, name, and balance.");
puts("Enter EOF to end input");
scanf("%d%29s%lf",&account, name, &balance);
while(!feof(stdin)){
fprintf(cfPtr,"%d %s %.2f\n",&account,name,&balance);
scanf("%d%29s%lf",&account,name,&balance);
}
}
return 0;
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.217.59
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1451860674.A.691.html
※ 編輯: rareone (140.114.217.59), 01/04/2016 06:39:04
推 LPH66: 我覺得你寫支程式 system("ls"); 看看比較快 01/04 07:29
→ LPH66: 基本上它會在所謂的「目前工作目錄」裡 01/04 07:30
→ LPH66: 但當你從 IDE 裡執行時那是哪裡各 IDE 有所不同 01/04 07:30
→ LPH66: 那這樣不如直接執行一個能告訴你目前目錄所在地的指令 01/04 07:31
→ LPH66: ls 是其一, pwd 也可以用 01/04 07:31
→ LPH66: (pwd 全名就是 print working directory, "印出工作目錄") 01/04 07:32
推 watermeter: 謝謝LP大,我去Google 看看 01/04 10:09