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

Similar documents
Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

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

PowerPoint プレゼンテーション

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

卒 業 研 究 報 告.PDF

超初心者用

untitled

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou

slide4.pptx

ohp08.dvi

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include

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

スライド タイトルなし

r08.dvi

untitled

ex14.dvi

02: 変数と標準入出力

1.ppt

02: 変数と標準入出力

(K&R 2.9) ~, &,, >>, << 2. (K&R 5.7) 3. (K&R 5.9) 4. (K&R 5.10) (argc argv atoi(), atof() ) 5. (K&R 7.5) (K&R 7.6) - FILE, stdin, stdout, std

PowerPoint プレゼンテーション

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

r07.dvi

ohp07.dvi

ファイル入出力

ohp03.dvi

memo

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

計算機プログラミング

ファイル入出力

r03.dvi

program.dvi

Microsoft Word - 06

新・明解C言語 ポインタ完全攻略

目次

情報処理演習 B8クラス

C言語入門

プログラミング基礎

double 2 std::cin, std::cout 1.2 C fopen() fclose() C++ std::fstream 1-3 #include <fstream> std::fstream fout; int a = 123; fout.open( "data.t

memo

joho07-1.ppt

第7章 有限要素法のプログラミング

Microsoft Word - no15.docx

Microsoft PowerPoint - kougi9.ppt

Microsoft Word - C.....u.K...doc

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

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

Microsoft Word - no204.docx

untitled

新版明解C言語 実践編

9.4 #define for while

新・明解C言語 実践編

Microsoft PowerPoint pptx

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

gengo1-12

+ +

C

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

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

gengo1-12

Microsoft PowerPoint - guidance.ppt

ファイル入出力と プロセス間通信 \(1\)

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

debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology

gengo1-12

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

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

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

ディジタル信号処理

lexex.dvi

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) * *

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

プログラミング及び演習 第1回 講義概容・実行制御

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)* (

データ構造

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D

tuat2.dvi

273? C

第5回お試しアカウント付き並列プログラミング講習会

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

A/B (2018/06/08) Ver kurino/2018/soft/soft.html A/B

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

PowerPoint Presentation

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

USB ID TA DUET 24:00 DUET XXX -YY.c ( ) XXX -YY.txt() XXX ID 3 YY ID 5 () #define StudentID 231

double float

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

Taro-リストⅢ(公開版).jtd

memo

ディジタル信号処理

プログラミング及び演習 第1回 講義概容・実行制御

PowerPoint Presentation

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

C ( ) C ( ) C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C mandata mandata ( ) name age income mandata ( ) mandat

comment.dvi

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

PowerPoint プレゼンテーション

Microsoft PowerPoint - kougi2.ppt

Microsoft PowerPoint - 10Com2.ppt

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

Transcription:

2008 3 10 1 mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) stream FILE ( man ) 40 ( ) %./a.out String : test Original : test (0x0xbfbd4160) Copy : test (0x0x804a050) %./a.out String : Hello Original : Hello (0x0xbfcb4860) Copy : Hello (0x0x804a050) %./a.out String : Hello World! 1

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n ) \n (scanf "%s" 1 ( \n \t ) Hello world! scanf("%s",str) Hello ) stdio.h stdin stdout stderr FILE (fgets 3 ) printf "%p" char *p; : printf("%p\n", p); string.h strlen size_t strlen(const char *s); s size_t int ( man ) malloc void *malloc(size_t size); size ( ) +1 ( \0 ) void * char * 2

mstrcpy malloc () 3

2 ( sin, cos, tan, log, exp ) ( ) 2 Please specify a function and a value 1 Undefined function 2 sin cos tan log exp libm % gcc () -lm -lm (libm) (sin cos tan [rad] log exp e(=2.71828... ) ) %./a.out Please specify a function and a value %./a.out cos Please specify a function and a value %./a.out sin 1 2 Please specify a function and a value %./a.out sin 1 Ans : 0.841471 %./a.out cos 1.570796325 Ans : 0.000000 %./a.out tan 2 Ans : -2.185004 %./a.out exp 1 Ans : 2.718282 %./a.out log 2.718282 Ans : 1.000000 %./a.out hoge 10 Undefined function : hoge stdio.h fprintf 4

int fprintf(file *stream, const char *format,...); stream format... printf string.h int strcmp(const char *s1, const char *s2); strcmp s1 s2 0 ( man ) stdlib.h double atof(const char *nptr); atof nptr double ( man ) 5

3 ( A Z ) ( a z ) ( 0 9 ) ( ) ( ) Usage : ( ) <file name> 2 2 Cannot open file : ( ) sample10-3_1.txt sample10-3_2.txt ~ren/pro3_2008_quiz/ %./a.out Usage./a.out <file name>. %./a.out sample10-3_1.txt Upper-case alphabets : 11 Lower-case alphabets : 147 Numbers : 0 Marks : 39 Total : 197 %./a.out sample10-3_2.txt Upper-case alphabets : 76 Lower-case alphabets : 801 Numbers : 0 Marks : 348 Total : 1225 %./a.out hoge.txt Cannot open file : hoge.txt fopen fopen fclose Usage... argv[0] 6

FILE *fopen(const char *path, const char *mode); path mode r w fopen NULL ( man ) int *fclose(file *fp); fp fopen FILE ( man ) int *fgetc(file *fp); fp fopen FILE getchar int ( man ) 7

4 (0 ) (0 1 ) ( a z ) ( A Z ) 1 1 2 1 2 3 void toupper(file *in, FILE *out); ( ) Cannot open file : ( ) sample10-4_1.txt sample10-4_2.txt sample10-4_3.txt ~ren/pro3_2008_quiz/ % echo test./a.out TEST % echo Hello World!./a.out test.txt % cat test.txt HELLO WORLD! %./a.out sample10-4_1.txt sample10-4_2.txt test2.txt % cat test2.txt PETER PIPER PICKED A PECK OF PICKLED PEPPERS LONDON BRIDGE IS FALLING DOWN, FALLING DOWN, FALLING DOWN. %./a.out sample10-4_3.txt sample10-4_2.txt sample10-4_1.txt test3.txt % cat test3.txt WHO KILLED COCK ROBIN? LONDON BRIDGE IS FALLING DOWN, FALLING DOWN, FALLING DOWN. PETER PIPER PICKED A PECK OF PICKLED PEPPERS %./a.out hoge.txt test4.txt Cannot open file : hoge.txt toupper 8

1 2 stdio.h fputc fputc int fputc(int c, FILE *stream); c (int ) stream fopen FILE 1 stdio.h stdin stdout stderr FILE fputc fgetc stream fopen toupper fgetc fputc (main ) toupper (stdin stdout fopen FILE ) 1 9

5 ID 1 Yamasaki 170 64 2 Ohmura 165 68 : 1 ID (EOF) (ID ) 40 malloc free next (person ) name struct person_list{ strcut person *next; int id; char *name; int height; int weight; }; Uasage : ( ) <file name> Cannot open file : ( ) 2 2 sample10-5.txt ~ren/pro3_2008_quiz/ %./a.out sample10-5.txt ID : 6 Name : Sato Height : 173 Weight : 66 ID : 5 Name : Imamura Height : 174 Weight : 64 ID : 4 Name : Suito Height : 172 Weight : 60 10

ID : 3 Name : Chishiro Height : 182 Weight : 65 ID : 2 Name : Ohmura Height : 165 Weight : 68 ID : 1 Name : Yamasaki Height : 170 Weight : 62 person list person list malloc malloc free fgets fgetc fscanf fscanf stdio.h int fscanf(file *stream, const char *format,...): stream FILE scanf EOF ( man ) 1 "%s" 1 "%d" "%f" < > < > < > 3 ( ) int a,b,c; : fscanf(fp, "%d%d%d", &a, &b, &c); a,b,c 11

< > <> < > int a,b; char str[40]; : fscanf(fp, "%d%s%d", &a, &str[0], &c); person list name char name 1 mstrcpy ( free mstrcpy malloc ) (person list ) struct person_list *head = NULL; struct person_list *p; : p = (strcut person_list *)malloc(sizeof(struct person_list)); /* p */ p->next = head; head = p; for (p = head; p!= NULL; p = p->next) { /* */ } 12