Microsoft PowerPoint - 10Com2.ppt

Similar documents
Cプログラミング1(再) 第2回

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

C言語入門

情報処理演習 B8クラス

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

memo

slide4.pptx

PowerPoint プレゼンテーション

slide5.pptx

Prog1_12th

PowerPoint プレゼンテーション

gengo1-12

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

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

ポインタ変数

gengo1-12

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

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

2006年10月5日(木)実施

Microsoft PowerPoint - kougi2.ppt

ファイル入出力

コマンドラインから受け取った文字列の大文字と小文字を変換するプログラムを作成せよ 入力は 1 バイトの表示文字とし アルファベット文字以外は変換しない 1. #include <stdio.h> 2. #include <ctype.h> /*troupper,islower,isupper,tol

ポインタ変数

Microsoft PowerPoint - kougi4.ppt

計算機プログラミング

Microsoft PowerPoint - guidance.ppt

PowerPoint プレゼンテーション

Microsoft PowerPoint pptx

02: 変数と標準入出力

ファイル入出力

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

演算増幅器

ポインタ変数

memo

DVIOUT

書式に示すように表示したい文字列をダブルクォーテーション (") の間に書けば良い ダブルクォーテーションで囲まれた文字列は 文字列リテラル と呼ばれる プログラム中では以下のように用いる プログラム例 1 printf(" 情報処理基礎 "); printf("c 言語の練習 "); printf

02: 変数と標準入出力

gengo1-12

< F2D837C E95CF CF68A4A94C5816A2E6A>

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

第2回講義:まとめ

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

PowerPoint プレゼンテーション

プログラミング基礎

Microsoft PowerPoint - kougi9.ppt

8 / 0 1 i++ i 1 i-- i C !!! C 2

PowerPoint プレゼンテーション

Microsoft PowerPoint - 計算機言語 第7回.ppt

JavaプログラミングⅠ

PowerPoint Presentation

Microsoft Word - no103.docx

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( )

PowerPoint プレゼンテーション

Prog1_6th

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

3.Cygwin で日本語を使いたい Cygwin で以下のコマンドを実行すると それ以降 メッセージが日本語になります export LANG=ja_JP.UTF-8 これは 文字コードを日本語の UTF-8 に設定することを意味しています UTF-8 は Cygwin で標準の文字コードで, 多

Microsoft PowerPoint - 14Chap17.ppt

スライド タイトルなし

joho07-1.ppt

今までの復習 プログラムで最低限必要なもの 入力 ( キーボードから ファイルから ) 出力 ( 画面へ ファイルへ ) 条件分岐 : 条件の成立 不成立により 異なる動作をする 繰り返し : 一定の回数の繰返し 条件成立の間の繰返し 関数の定義 関数の呼び出し C ではそれ以外に ポインタ データ

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

02: 変数と標準入出力

02: 変数と標準入出力

Prog1_10th

全体ロードマップ インターネット電話 音の符号化 ( 信号処理 ) 今日 音の録音 再生 ネットワーク ( ソケット ) プログラミング ファイル入出力 インターネットの基礎 C プログラミング基礎

Microsoft Word - 06

memo

Microsoft PowerPoint - prog04.ppt

Microsoft PowerPoint - Borland C++ Compilerの使用方法(v1.1).ppt [互換モード]

C C UNIX C ( ) 4 1 HTML 1

データ構造

練習&演習問題

講習No.9

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

第9回 配列(array)型の変数

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

講習No.1

1.ppt

Microsoft PowerPoint - bp02.ppt

PowerPoint プレゼンテーション

Microsoft PowerPoint pptx

Microsoft PowerPoint - 5Chap15.ppt

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

※ ポイント ※

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

PowerPoint プレゼンテーション

gengo1-6

PowerPoint Presentation

超初心者用

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

PowerPoint プレゼンテーション

卒 業 研 究 報 告.PDF

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

PowerPoint Presentation

:30 12:00 I. I VI II. III. IV. a d V. VI

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

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

新・明解C言語 実践編

Microsoft Word - Training10_プリプロセッサ.docx

memo

Transcription:

リダイレクトとは コマンドプロンプト操作 (2) リダイレクト パイプ 標準入出力プログラム コマンド行引数 関数 system() 今日のポイン リダイレクトとパイプを使いこなそう 標準入力 標準出力 標準エラー出力を " デフォルト " から別のファイルに割り当てる操作 " デフォルト " は CON ( コンソール ) で 実際の入力はキーボード 出力はディスプレイ 標準入力は 0< ファイル名 < ファイル名 標準出力は 1> ファイル名 > ファイル名 標準エラー出力は 2> ファイル名 追加出力は >> ファイル名 2>> ファイル名 リダイレクトの練習 (1) リダイレクトの練習 (2) Z: nyumon2>dir > foo.txt Z: nyumon2>dir /f 2> err.txt Z: nyumon2>more < foo.txt Z: nyumon2>more < err.txt Z: nyumon2>dir /w >> foo.txt Z: nyumon2>dir /v 2>> err.txt Z: nyumon2>more < foo.txt Z: nyumon2>more < err.txt foo.txt に出力 err.txt にエラー出力 foo.txt の内容を表示 foo.txt に追加出力 err.txt に追加エラー出力 foo.txt の内容を再表示 Z: nyumon2>dir > con Z: nyumon2>dir /f 2> con Z: nyumon2>more < con > goo.txt abcdefghijklmnopqrstuvwxyz<enter> Ctrl-z<Enter> Z: nyumon2>more < goo.txt 先週作った Z: nyumon2 hello に行き コンソールに出力 キーボード入力を goo.txt に保存 ファイルの終わりを表す記号 ( 教科書 p.139 問題 14.3) Z: nyumon2 hello>hello > hello.txt Z: nyumon2 hello>more < hello.txt

パイプとは ファイル保存をせずに直接 次のプログラムにデータを受け渡す方法 縦棒 を使って連結する 標準入力 標準出力のコマンド プログラム に用いる 並べ替えのコマンド Z: nyumon1>dir /s /b sort more 標準入力 標準出力のコマンド more: ページごとの出力 sort: 並べ替え find: 文字列検索 Z: nyumon1>dir /s find "hello" findstr: 高度な文字列検索 Z: nyumon1>findstr /s "fopen" *.c 標準出力標準入力 / 標準出力 標準入力 / 標準出力 help コマンドで調べてみよう 編集用コマンド 標準エラー出力を用いたプログラム notepad ( メモ帳 ) Z: nyumon2 hello>notepad hello.c write ( ワードパッド ) Z: nyumon2 hello>write Z: nyumon2 hello>write hello.c devenv ( 開発環境 ) Z: nyumon2 hello>devenv hello.c Z: nyumon2 hello>hello.c 新規のとき hello.c を編集し hello2.c に名前を変えて保存 CL コマンドを用いてコンパイル (cl hello2.c) /* hello world program 2 */ printf("hello world! n"); fprintf(stderr,"error message! n"); この行を追加 fprintf: ファイルへの出力 ( 教科書 p.130) stderr: 標準エラー出力

標準エラー出力を用いたプログラムの実行 リダイレクトを用いて実行してみる Z: nyumon2 hello>hello2 Z: nyumon2 hello>hello2 > hello2.txt Z: nyumon2 hello>hello2 2> err2.txt または Z: nyumon2 hello>hello2 >hello2.txt 2>err2.txt Z: nyumon2 hello>more < hello2.txt Z: nyumon2 hello>more < err2.txt 標準入力 標準出力を用いたプログラム 以下のプログラムを typ.c と名づけて保存し コンパイルせよ ( 自作コマンドのための第 1 歩 ) /* typ.c: stdin type */ stdin から変数 c に1 文字分入力 int c; while ((c=fgetc(stdin))!= EOF) fputc(c,stdout); ファイルの終わりまで続ける stdout に1 文字出力 fgetc(): ファイルから 1 文字入力 fputc(): ファイルに 1 文字出力 CL コマンドを用いること stdin: 標準入力 EOF: ファイル終端 標準入力表示プログラムの実行 Z: nyumon2>typ < typ.c... Z: nyumon2>typ abc... abc... 123... 123... ^Z Ctrl-z を入力 Z: nyumon2>dir typ type コマンドや more コマンドと動作を比べてみよ 教科書 p.139 問題 14.3 参照 万一 プログラムが終われなくなったら Ctrl-c で強制終了 コマンド行引数 プログラムの後にオプションを付けられるようにする ( 自作コマンドのための第 2 歩 ) main(void) main(int argc, char *argv[ ]) int argc: コマンド行の文字列数 char *argv[ ]: コマンド行の文字列配列例 : Z: nyumon2>mainarg 1.2345 abcde!"#$%&'() argc=4 argv[0]="mainarg" argv[1]="1.2345" argv[2]="abcde" argv[3]="!#$%&'()"

コマンド行確認プログラム mainarg.c を作成し コンパイル 実行せよ /* mainarg.c: main argument test */ int main(int argc, char *argv[]) int i; printf("argc = %d n", argc); for (i = 0; i < argc; i++) printf("argv[%d] = "%s " n", i, argv[i]); エスケープ系列 ( 教科書 p.180) 関数 system( ) 関数 system( ) を用いると プログラム内からコマンドプロンプトのコマンドが利用できる stdlib.h ヘッダが必要 /* hello world program 3 */ #include <stdlib.h> system("cls"); printf("hello world! n"); hello.c にこの行を追加 この行も追加 hello3.c cls について調べてみよう 制御コード 2 " 2 重引用符 教科書 p.180 表 A.2 ' 単一引用符 t 水平タブ 円マーク ( ハ ックスラッシュ ) /* hello world program 4 */ hello4.c #include <syslib.h> system("cls"); printf(" 'hello world! ' n"); この部分を追加 Office アプリケーションを開く Excel の実行ファイル (Excel.exe) のありかを確認し 直接実行するプログラムを作る /* Excel exec program */ #include <stdlib.h> system(" "C: Program Files " "Microsoft Office " "Office11 Excel.exe ""); excel2.c Word(Winword.exe) や PowerPoint(Powerpnt.exe) を開くプログラムも作ってみよ 文字列を途中で改行するときは必ずダブルクォートで区切る コマンドにスペースがあるときは全体をダブルクォート ( ") でくくる

スキルアップタイム ~ コマンド行引数を用いた自作コマンドの作成 ~ コマンド行で指定した文字の数をカウントする chc.c を完成させよう /* chc.c: char counter */ int main(int argc, char *argv[]) int c, cnt=0; while ((c=fgetc(stdin))!= EOF) if ( ) ; printf(" ", ); 文字数カウンタ chc の実行例 chc のソースファイルで試した例 Z: nyumon2>chc i < chc.c i: 10 Z: nyumon2>chc abc < chc.c a: 6 万一 プログラムが終われなくなったら Ctrl-c で強制終了 argc = 2 argv[0] = "chc" argv[1] = "i < chc.c" argc = 2 argv[0] = "chc" argv[1] = "abc < chc.c" スキルアップタイム ( オフ ション ) excel2.c を改良し ファイル名を指定できるようにせよ (excel3.c) コマンド行でファイル名を指定 excel 実行用文字列に argv[1] を連結 strcat 関数の利用 excel 実行用文字列は初期値で与える argc = 1 のときは連結しない 連結された文字列を system 関数に渡す