用c開啟檔案

Home Home
引用 | 編輯 UBL
2005-06-04 23:01
樓主
推文 x0
挑戰範例區..!!
也請各位看看有沒有什麼地方要改進的...
斜線怪怪的
if((fptr = fopen("D:\C\score.txt", "r")) != NULL) /*開啟檔案*/
此為雙斜線...

/*要先建一個文字檔輸入姓名和成績
預設位置為"D:\C\score.txt"
有問題再提出來大家起討論吧...by UBL*/

#include <stdio.h>
#include <stdlib.h>

s ..

訪客只能看到部份內容,免費 加入會員



獻花 x0
引用 | 編輯 ronlain
2005-06-04 23:40
1樓
  
struct data *ptr = &student;/*宣告指向結構的指標變數*/
這一行 怪怪的 表情

獻花 x0
引用 | 編輯 MarkTzen
2005-06-07 00:54
2樓
  
struct data *ptr = &student;
喔…不會啊…我覺得還挺正常的!
型態struct data *ptr指向student的位置(&student)。。。
還是指???什麼問題嗎?看起來不太順嗎?

獻花 x0
引用 | 編輯 ronlain
2005-06-07 22:25
3樓
  
你已經宣告一個全域變數 就不需要再宣告一個指標
還有寫程式最好把變數放在function內 不然很容易命名污染

我覺得寫code不只是精簡就是好 要讓其他人容易讀
if((fptr = fopen("D:Cscore.txt", "r")) != NULL)   /*開啟檔案*/
這種我會把他拆成幾行 且先回 return

fptr = fopen("D:Cscore.txt", "r");

if( fptr == NULL){
  printf ("error!!");
  return 0;
}

不好意思 我在業界寫了幾年code所以會比較龜毛
印度人寫的code的很好讀 即使只是做一個小動作也會把他拆的很乾淨
良好的寫code習慣對以後工作很有幫助喔 表情

獻花 x1