[問題]檔案的輸入

看板C_and_CPP (C/C++)作者 (有緣人)時間15年前 (2010/12/03 20:25), 編輯推噓2(209)
留言11則, 5人參與, 最新討論串1/1
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *fp; int test[NUM]; int i,j; fp=fopen("test1.txt","w"); if(fp==NULL) { printf("not open file\n"); return 1; } else{ printf("open file\n"); } printf("input sum\n"); for(i=0;i<NUM;i++) { scanf("%d",&test[i]); } for(j=0;j<NUM;j++) { fprintf(fp,"NO.%-5d%d\n",j+1,test[j]); } printf("write finish\n"); fclose(fp); system("PAUSE"); return 0; } 這是一般寫入的程式可是這是固定路徑如果我要指定到我想要的路徑 要如何撰寫? 我要讀取一個.txt檔...可是我想指定 路徑 讀取.... 那個路徑可以隨意更動,要怎麼寫? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.37.164.192

12/03 20:32, , 1F
fopen("test1.txt", <= 把 test1.txt 改成你要的檔案就好
12/03 20:32, 1F

12/03 20:35, , 2F
我要的是路徑例如c:/work它就會到這個路徑找檔案
12/03 20:35, 2F

12/03 20:40, , 3F
chdir function
12/03 20:40, 3F

12/03 20:53, , 4F
在DEV C++可以降做嗎?
12/03 20:53, 4F

12/03 20:55, , 5F
0.0
12/03 20:55, 5F

12/03 21:14, , 6F
所以是不行?
12/03 21:14, 6F

12/03 21:17, , 7F
當然可以... 改路徑只是檔名前面的url不一樣而已
12/03 21:17, 7F

12/03 21:22, , 8F
阿..那不叫URL XD
12/03 21:22, 8F

12/03 22:40, , 9F
http://codepad.org/w7oG3r0f 就只是多個輸入的動作,
12/03 22:40, 9F

12/03 22:40, , 10F
當然你要寫死也可
12/03 22:40, 10F

12/03 23:24, , 11F
喔…又學到一個新名詞 XD 叫 URL 哈哈哈…
12/03 23:24, 11F
文章代碼(AID): #1C-E6-sv (C_and_CPP)
文章代碼(AID): #1C-E6-sv (C_and_CPP)