讀取不同格式檔案的兩種方式

2021-07-22 21:21:47 字數 1299 閱讀 3250

方式一:-----------含有多行,每行含有一列資料

int filereader(char * file,double * a)

for(int i=0;fscanf(fp1,"%lf",a+i)!=eof;i++);//從輸入檔案連續讀取浮點型數到陣列a

fclose(fp1);//關閉輸入檔案

return 1;

}

方式二:-----------含有多行,每行含有多列資料

char * topo[5000];  //將topo賦給buff;

int spec = 5000; //表示行數

#denfine max_line_len 4000

int read_file(char ** const buff, const unsigned int spec, const char * const filename)

//  print("open file %s ok.\n", filename);

char line[max_line_len + 2];

unsigned int cnt = 0;

while ((cnt < spec) && !feof(fp))

fclose(fp);

return cnt;

}

//對topo進行操作,取出每一列的資料

int edge_num = 5000;

char * delim = ",|\n";  //以制定的格式進行列的分割

char *p = null;

int i = 0, j = 0;

int value = 0;

for(i=0; i

j++;

p = strtok(null, delim);

}

linux幾種不同格式檔案安裝方式

linux幾種不同格式檔案的安裝方式使用linux系統的人都知道,linux系統下軟體的安裝可不像windows下,雙擊,一路next下去就可以,在linux下常用的軟體主要有deb,rpm,tar.gz,bin等格式,那麼下面我給大家講解這些軟體的安裝方法。a deb包,這種最簡單了,如果是ubu...

config檔案的兩種讀取方式

1.專案預設的讀取webconfig中的,如下 1 public voidgetaccounts 2 3 34 35 accounts.add account 36 37 38 39 40 41 42 43 2.指定位置的讀取方式 自己新增的config檔案 1 public void getacc...

Perl讀取檔案的兩種常用方式

整體讀入,逐行處理 open file,home chenmi bashrc die cannot open the file n linelist foreach eachline linelist close file 逐行讀入,邊讀邊處理 open file,home chenmi bashr...