練習&演習問題

Similar documents
ファイル入出力

ファイル入出力

Microsoft Word - Cプログラミング演習(9)

Taro-ファイル処理(公開版).jtd

PowerPoint Presentation

C言語講座 ~ファイル入出力編~

gengo1-12

1. ファイルにアクセスするには ファイルにアクセスするには 1. ファイルを開く 2. アクセスする 3. ファイルを閉じるという手順を踏まなければなりません 1.1. ファイルを読み込む まずはファイルの内容を画面に表示させるプログラムを作りましょう 開始 FILE *fp char fname

gengo1-12

プログラミング基礎

gengo1-12

ポインタ変数

情報処理演習 B8クラス

Microsoft Word - Cプログラミング演習(12)

演算増幅器

Microsoft Word - no15.docx

Microsoft PowerPoint - 第3回目.ppt [互換モード]

プログラミング基礎

Microsoft Word - no103.docx

計算機プログラミング

Microsoft PowerPoint - kougi6.ppt

データ構造

PowerPoint プレゼンテーション

Microsoft PowerPoint - prog04.ppt

Prog1_12th

2006年10月5日(木)実施

‚æ2›ñ C„¾„ê‡Ìš|

Microsoft PowerPoint - program.ppt [互換モード]

Microsoft Word - Cプログラミング演習(10)

02: 変数と標準入出力

02: 変数と標準入出力

C 言語講座 Vol 年 6 月 26 日 CISC

Microsoft PowerPoint pptx

C プログラミング演習 1( 再 ) 2 講義では C プログラミングの基本を学び 演習では やや実践的なプログラミングを通して学ぶ

PowerPoint プレゼンテーション

Microsoft PowerPoint - 14th.ppt [互換モード]

PowerPoint プレゼンテーション

Microsoft Word - no204.docx

データ構造

ポインタ変数

1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

※ ポイント ※

文字列 2 前回の授業ではコンピュータ内部での文字の取り扱い 文字型の変数 文字型変数への代入方法などを学習した 今回は 前回に引き続き 文字処理を学習する 内容は 標準入出力 ( キーボード ディスプレイ ) での文字処理 文字のファイル処理 文字を取り扱うライブラリ関数である 標準入出力 Lin

PowerPoint プレゼンテーション

gengo1-6

XMPによる並列化実装2

PowerPoint プレゼンテーション

ゲームエンジンの構成要素

slide4.pptx

プログラミング演習 土曜日(Q組)

<4D F736F F D20438CBE8CEA8D758DC03389F0939A82C282AB2E646F63>

プログラミング演習3 - Cプログラミング -

超初心者用

演算増幅器

memo

Microsoft PowerPoint - kougi2.ppt

memo

Prog1_15th

program.dvi

Microsoft PowerPoint - kougi11.ppt

V

Microsoft PowerPoint - OOP.pptx

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology

PowerPoint Presentation

講習No.12

画像ファイルを扱う これまでに学んだ条件分岐, 繰り返し, 配列, ファイル入出力を使って, 画像を扱うプログラムにチャレンジしてみよう

プログラミング方法論 II 第 14,15 回 ( 担当 : 鈴木伸夫 ) 問題 17. x 座標と y 座標をメンバに持つ構造体 Point を作成せよ 但し座標 は double 型とする typedef struct{ (a) x; (b) y; } Point; 問題 18. 問題 17 の

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdio.h> #define InFile "data.txt" #define OutFile "sorted.txt" #def

ex14.dvi

Microsoft Word - cpro_m_13.doc

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdiu.h> #define InFile "data.txt" #define OutFile "surted.txt" #def

C 資料 電脳梁山泊烏賊塾 ファイルの入出力 C++ のバイナリファイル入出力 初めに 此処では Visual Studio 2017 を起動し 新しいプロジェクトで Visual C++ の Windows デスクトップを選択し Windows コンソールアプリケーションを作成する

テキスト処理第 2 回 田中哲産業技術総合研究所情報技術研究部門 akira/textprocess/

slide5.pptx

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

memo

FORTRAN( と C) によるプログラミング 5 ファイル入出力 ここではファイルからデータを読みこんだり ファイルにデータを書き出したりするプログラムを作成してみます はじめに テキスト形式で書かれたデータファイルに書かれているデータを読みこんで配列に代入し 標準出力に書き出すプログラムを作り

Microsoft Word - no12.doc

ポインタ変数

Microsoft Word - 3new.doc

Microsoft PowerPoint - prog06.ppt

ポインタ変数

<4D F736F F D20438CBE8CEA8D758DC F0939A82C282AB2E646F63>

Microsoft PowerPoint - CproNt11.ppt [互換モード]

PowerPoint Presentation

Taro-再帰関数Ⅱ(公開版).jtd

Microsoft PowerPoint - kougi8.ppt

untitled

ディジタル信号処理

kiso2-09.key

Microsoft PowerPoint - lec4.ppt

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

PowerPoint Presentation

file"a" file"b" fp = fopen("a", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen("b", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose

Microsoft Word - Cプログラミング演習(8)

Microsoft Word - no202.docx

Microsoft PowerPoint - lec10.ppt

基礎プログラミング2015

プログラミング演習3 - Cプログラミング -

Transcription:

練習問題 ファイル入出力

練習問題 1 ファイルへのデータ出力 配列 a[ ] の値をファイル data.txt に出力するプログラムを作成しなさい #include <stdio.h> #include <stdlib.h> /* srand(), rand() */ #include <time.h> /* time() */ int main(void) { int i; double a[5]; char filename[21] = "data.txt";???? *fp; /* ファイルポインタの宣言 */ /* ファイルへデータを書き込む */ for(i = 0; i < 5; i++)???????(fp, "%.2lf n", a[i]); fclose(fp); /* 乱数発生 (0~1000 までの乱数を 100 で割った値 ) */ srand((unsigned int)time(null)); for(i = 0; i < 5; i++){ a[i] = rand() % 1000 / 100.0; /* ファイルを書き込みモードでオープンする */ if((fp =?????(filename,????)) == NULL){ printf(" ファイルオープンに失敗しました. n"); data.txt 1.23 2.45 3.56 4.78 5.91 data.txt ファイルができるので, メモ帳などで確認してみる

練習問題 2 ファイルからのデータ入力 練習問題 1 で作成されたファイル data.txt からデータを読み込んで配列 a[ ] に格納したあと, 配列 a[ ] の合計を計算するプログラムを作成しなさい #include <stdio.h> #define N 5 int main(void) { int i, n; double a[n], sum; char filename[21] = "data.txt"; FILE *fp; /* ファイルを読み込みモードでオープンし */ /* ファイルポインタ fp に接続 */ if((?? = fopen(filename,????)) == NULL){ printf(" ファイルオープンに失敗しました. n"); /* ファイルの最後まで (EOF まで ) 読み込む */ i = 0; while(??????(??, "%lf", &a[i])!= EOF){ i++; n = i; sum = 0.0; for(i = 0; i < n; i++){ printf("a[%d] = %.2lf n", i, a[i]); sum += a[i]; printf(" 合計 :%.2lf n", sum);??????(fp); /* ファイルをクローズ */ data.txt 1.23 2.45 3.56 4.78 5.91 読み込む a[0] a[1] a[2] a[3] a[4] 1.23 2.45 3.56 4.78 5.91

練習問題 3 ファイルからの文字列入力 英文ファイル abstract.txt に含まれる 'a' および 'A' の文字数を数えるプログラムを作成しなさい #include <stdio.h> #define N 256 int main(void) { int i, counta; char buf[n]; char fnam[21] = "abstract.txt"; FILE *fp; /* ファイルを読み込みモードでオープン */ if((fp = fopen(fnam,????)) == NULL){ printf("[%s]: オープンに失敗 n", fnam); counta = 0; /* ファイルから 1 行読み込むのを NULL まで繰り返す */ while(?????(buf, N,??)!= NULL){ i = 0; while(buf[i]!=????){ /* 文字列の最後まで */ /* 文字列の文字が 'a' もしくは 'A' であるかどうか */ if(buf[i] ==??? buf[i] ==???){????????? /* そうであれば counta を +1*/???? /* 次の文字を見る */ fclose(fp); printf(" a および A は "); printf("%d 文字含まれる. n", counta);

練習問題 3 ファイルからの文字列入力 ( 解説 ) abstract.txt A new method is proposed for detection of the temporal changes using 3-dimensional segmentation. The method is a kind of clustering methods for temporal changes.[ 改行 ] In the method, multi-temporal images form a image block in 3-dimensional space; x-y plane and time axis. [ 改行 ] The image block is firstly divided into spatially uniform sub-blocks by applying binary division process. [ 改行 ] The division rule is based on the statistical t-test using Mahalanobis distance between spatial coefficient vectors of a local regression model fitted to neighboring sub-blocks to be divided. [ 改行 ] The divided sub-blocks are, then, merged into clusters by using a clustering technique. [ 改行 ] The block based processing such as the spatial segmentation technique is very effective in reduction of apparent changes due to noise. [ 改行 ] Temporal change is detected as a boundary perpendicular to the time axis in the segmentation result. [ 改行 ] The proposed method is successfully applied to actual multitemporal and multispectral LANDSAT/TM images. [EOF] ファイルから最大 255 文字読み込み, に格納 char = ~ " A new method is ~ changes. " fgets によって [ 改行 ] まで読み込まれる [0] A n e w c h a n すなわち [1] [2] [3] [4] [5] [6] [7] [8] g m e t ~ [90] [91] [92] [93] [94] [95] [96] [97] [98] e s. 0 実際には [ 改行 ] のコードが入る

練習問題 3 ファイルからの文字列入力 ( 解説 ) 文字列 に格納されている文字を 1 文字ずつ検索していく [0] [1] [2] [3] [4] [5] [6] [7] [8] [90] [91] [92] [93] [94] [95] [96] [97] [98] A n e w m e t ~ c h a n g e s. 0 'a' or 'A'? 真 counta を +1 して次の文字を見る [0] [1] [2] [3] [4] [5] [6] [7] [8] [90] [91] [92] [93] [94] [95] [96] [97] [98] A n e w m e t ~ c h a n g e s. 0 'a' or 'A'? 偽 何もしないで次の文字を見る [0] [1] [2] [3] [4] [5] [6] [7] [8] [90] [91] [92] [93] [94] [95] [96] [97] [98] A n e w m e t ~ c h a n g e s. 0 ' 0' であれば, 終了

練習問題 3 ファイルからの文字列入力 ( 解説 ) abstract.txt A new method is proposed for detection of the temporal changes using 3-dimensional segmentation. The method is a kind of clustering methods for temporal changes.[ 改行 ] In the method, multi-temporal images form a image block in 3-dimensional space; x-y plane and time axis. [ 改行 ] The image block is firstly divided into spatially uniform sub-blocks by applying binary division process. [ 改行 ] The division rule is based on the statistical t-test using Mahalanobis distance between spatial coefficient vectors of a local regression model fitted to neighboring sub-blocks to be divided. [ 改行 ] The divided sub-blocks are, then, merged into clusters by using a clustering technique. [ 改行 ] The block based processing such as the spatial segmentation technique is very effective in reduction of apparent changes due to noise. [ 改行 ] Temporal change is detected as a boundary perpendicular to the time axis in the segmentation result. [ 改行 ] The proposed method is successfully applied to actual multitemporal and multispectral LANDSAT/TM images. [EOF] EOF( ファイルの終わり ) まで読み込み 検索の処理を繰り返す