どーにかなるよ。うん。 | coconuz info processor

どーにかなるよ。うん。

ファイルの書き込み

http://homepage3.nifty.com/mmgames/c_guide/17-01.html


1.密と疎 30、60、90、120、150

report1で書き込む内容(行列データ)

int main(void)
{
int i = 100;
FILE *file;
file = fopen("d.txt","w");
fprintf(file,"%d",i);
fclose(file);
return 0;
}
report3で回数記録をファイル出力

FILE *file;


ーーーーーーーーカウント=0

file = fopen("d.txt","w");
fprintf(file,"%d",i);
fclose(file);

ーーーーーーーカウント>0

file = fopen("d.txt","a");
fprintf(file,"%d",i);

------------------

終了後

fclose(file);

ーーーーーーーーーーーーーーーーーもしくは

②gnuplotつかってファイルをつくってみるテスト

6 FILE *file, *gp;
7 char *data_file;
8 int i;
9 double dx, x, y;
10
11 /*------ データファイル作成 ---------- */
12 data_file="out.dat";

ーーーーーーーーカウント=0

file = fopen("out.dat","w");
fprintf(data,"%f\t%f\n", 回数, 違反点数);
fclose(file);

ーーーーーーーカウント>0

file = fopen("out.dat","a");

fprintf(data,"%f\t%f\n", 回数, 違反点数);


21 fclose(file);
22
23 /*------ グラフの作成 ---------- */
24 gp = popen("gnuplot -persist","w");
25 fprintf(gp, "set xrange [0:回数]\n");
26 fprintf(gp, "set yrange [0:違反点数]\n");
27 fprintf(gp, "plot \"%s\" with lines linetype 1 title \"sin\"\n",data_file);
28 pclose(gp);
29

2.解を先に求めたファイルを使う→カンマ付きのファイルを読み込み

ーーーーーーーーーーーーーーーーーーーーーー

int main(void)
{
int i,j;
FILE *file;
file = fopen("test.txt","r");

for(i=0;i<N;i++){
for(j=0;j<N;j++){

fscanf(file,"%d,",&map[i][j]);

}
}

fclose(file);
printf("i = %d : j = %d\n",i,j);
return 0;
}


ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

●最優先事項→グラフ作成。

タイミングは、

違反点数が決定するタイミング!!!で、格納。

関数write graph 引数 回数 違反点数

●カンマ付きデータの読み込み

一度てすとしてみること。