ex12.dvi

Similar documents
ex14.dvi

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

joho07-1.ppt

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

lexex.dvi

求人面接資料PPT

tuat1.dvi

10

untitled

02: 変数と標準入出力

橡Pro PDF

APR. JUL. AUG. MAY JUN. 2

/* sansu1.c */ #include <stdio.h> main() { int a, b, c; /* a, b, c */ a = 200; b = 1300; /* a 200 */ /* b 200 */ c = a + b; /* a b c */ }

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±

02: 変数と標準入出力


July prog11-02.c /*, */ /* $Id: prog11-02.c,v :48:07+09 naito Exp $ */ #include <stdio.h> #define N 10 int main(int argc, cha

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >=

ohp03.dvi

02: 変数と標準入出力

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

18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf("hello World\n"); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o


ex01.dvi

初めに:

r07.dvi

ohp07.dvi

(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

解きながら学ぶC++入門編

極地研 no174.indd

untitled

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

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

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

r08.dvi

広報ひめじ2015年9月号

広報ひめじ2015年8月号

????? 1???

‚æ4›ñ

untitled

ohp08.dvi

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

1.ppt

r03.dvi

char char 1 signed char unsigned char ( ; single-quote 0x27) ASCII Japan Advanced Institute of Science and Technology

& & a a * * ptr p int a ; int *a ; int a ; int a int *a

(2 Linux Mozilla [ ] [ ] [ ] [ ] URL 2 qkc, nkc ~/.cshrc (emacs 2 set path=($path /usr/meiji/pub/linux/bin tcsh b

_2009MAR.ren

1 ( )

卒 業 研 究 報 告.PDF

ex01.dvi

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

本文

C B


PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

1 4 2 EP) (EP) (EP)

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

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

ポインタ変数

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

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

contents

BW BW

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

(300, 150) 120 getchar() HgBox(x, y, w, h) (x, y), w, h #include <stdio.h> #include <handy.h> int main(void) { int i; double w, h; } HgO

Microsoft Word - 3new.doc

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

有明海・八代海総合調査評価委員会 委員会報告書 別添資料

Print

新版明解C言語 実践編


PowerPoint Presentation

kiso2-09.key

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

超初心者用

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

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡

02: 変数と標準入出力

6-1

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² –

slide5.pptx

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

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

新・明解C言語で学ぶアルゴリズムとデータ構造

1. 入力した文字列を得る 1.1. 関数 scanf() を使う まずは関数 scanf() を使ったプログラムを作ってみましょう 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: #include<stdio.h> #define SIZE 128 main(

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

13koki_koza.indd

x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x i ) A(x i ) = h 2 {f(x i) + f(x i+1 ) = h {f(a + i h) + f(a + (i + 1) h), (2) 2 a b n A(x i )

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

新・明解C言語 実践編

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

PowerPoint プレゼンテーション

WinHPC ppt

tuat2.dvi

C言語によるアルゴリズムとデータ構造

0ニ0・モgqNャX1TJf・

実際の株価データを用いたオプション料の計算

Step1 Step2 Step3 Step4 Step5 COLUMN.1 Step1 Step2 Step3 Step4 Step5 Step6 Step7 Step8 COLUMN.2 Step1 Step2 Step3 Step4 Step5 COLUMN.3 Step1 Step2 Ste

XMPによる並列化実装2

Transcription:

1 0. C, char., char, 0,. C, ("),., char str[]="abc" ; str abc.,, str 4. str 3. char str[10]="abc" ;, str 10, str 3., char s[]="abc", t[10] ;, t = s. ASCII, 0x00 0x7F, char., "abc" 3, 1. 1 8 256, 2., 2 1. 4. Shift JIS Microsoft Windows. 0x80 8. EUC-JP Unix. 0x80 8. gcc, EUC-JP,. JIS (ISO 2022-JP) 0x7F 7. ASCII 3. Unicode Unicode,,. 3 (Shift JIS,

2 EUC-JP, JIS),,. Unicode,. Unicode,,. Unicode UTF-8, 8 MacOS X. UTF-8 1 2 3., Unicode UCS-2, UCS-4, UTF-7, UTF-16, UTF-32., char[]=" ", EUC-JP Shift JIS, 10.., int foo(int a[]).., extern int foo(int []);.,,,., int. ex12-1.c. int *pn, *pm pn pm int., int. &,. &. *,. *. pn = &n pn n, pn n. *pn = 2, pn 2., pn n, n 2. pm = pn, pm pn., pn n, pm n, pm n.

3 printf %p,.,. ex12-2.c.,. int a[10], char s[11], int, char., int *pa, char *ps, int, char. ps = s ps s. ex12-1.c,,.,, s s., s[0]., ps = s ps = &s[0]. char ps ps+1., ps s[0], ps+1 s[1]. *(ps+i) s[i]. char ps, ps char s, *(ps+i) ps[i]. int pa pa+1., char,.,,., pa a[0], pa+1 a[1]. *(pa+i) a[i]., pa+1. a[i] *(a+i).. ex12-3.c, a main b. int foo_0(int a),,., main foo_0,. int foo_1(int *a),,., main foo_1,...

4,,. ex12-4.c, a. for(i=0;i<=len;i++) *(b+i) = *(a+i) ; len a b. Null Terminate, while((*(c+i) = *(a+i))) i += 1 ; a c. char *_strcpy(char *t, char *s), char., char a, a,,,. char *_strcpy(char *t, char *s), while((*(t+i) = *(s+i))) i += 1 ;, s t., char *strcpy(char *t, const char *s), while((*t++ = *s++)) ; s t. t++ t,, t t. char. const char *s const,,..,., char a[n], e[n] while((*e++ = *a++)) ;.. ex12-5.c, char a[] = "message" ; char *p = "message" ;.. p, for(i=0;*(p+i);i++) printf("%s\n", p+i) ; for(;*p;p++) printf("%s\n", p) ;. a, for(i=0;*(a+i);i++) printf("%s\n", a+i) ;, for(;*a;a++) printf("%s\n", a) ;

5 a++., a[0] = M ;,, p[0] = M ;.. char a[] = "message" ; 8 char, a 8 message. a., p char *p = "message" ;,, char p, message p., p, a., p message,, p[0] = M,. C. ex12-6.c,, swap.,. c = a ; a = b ; b = c ; a, b, c. void not_swap_char(char a, char b)., ex12-3.c,. char, char. void swap_char(char *a, char *b) int, int. void swap_int(int *a, int *b), swap_char int.

6 swap_char((char *)&n, (char *)&m) ;., n, m int, &n, &m, int, int.,., (char *) char.,,,.,,., swap_char int,., swap_char *a char, c = *a a. swap_int char, (Bus Error)..,.,,. ex12-7.c,,,. void swap(void *a, void *b, size_t size). void *,.,, char. ex12-8.c char *str[3], char 3. char **pstr, char. char *str[3] str[0] char, str char., char **pstr. char *str_array[] = "abc", "defg", "hijkl", char., str_array[i] i. main argv, argc.

7 ex12-9.c char *strchr(const char *s, int c), s c., NULL. NULL. char *, p = strchr(s, i ) p printf. p-s, p s.., p-s unsigned int unsigned long typedef size_t.. ex12-1.c /* $Id: ex12-1.c,v 1.3 2004-06-30 08:01:11+09 naito Exp $ */ #include <stdio.h> int main(int argc, char **argv) int n = 1, m = 3 ; int *pn, *pm ; pn = &n ; /* printf("*pn = %d, *pm = %d, n = %d, m = %d\n", *pn, *pm, n, m) ; */ printf("*pn = %d, n = %d, m = %d\n", *pn, n, m) ; *pn = 2 ; /* n */ printf("*pn = %d, n = %d, m = %d\n", *pn, n, m) ; /* printf("*pn = %d, *pm = %d, n = %d, m = %d\n", *pn, *pm, n, m) ; */ pm = pn ; /* pm */ printf("*pn = %d, *pm = %d, n = %d, m = %d\n", *pn, *pm, n, m) ; pn = &m ; /* pn, pm */ printf("*pn = %d, *pm = %d, n = %d, m = %d\n", *pn, *pm, n, m) ; *pm = 5 ; /* n, m */ printf("*pn = %d, *pm = %d, n = %d, m = %d\n", *pn, *pm, n, m) ; printf("pn = %p\n", pn) ; printf("pm = %p\n", pm) ; printf("address of n = %p\n", &n) ; printf("address of m = %p\n", &m) ;

8 ex12-2.c /* $Id: ex12-2.c,v 1.4 2004-06-25 11:29:32+09 naito Exp $ */ /* */ #include <stdio.h> int main(int argc, char **argv) int a[10] = 0,1,2,3,4,5,6,7,8,9 ; char s[11] = "ABCDEFGHIJ" ; int *pa ; char *ps ; int i ; ps = s ; printf("%c %c %p %p\n", *ps, s[0], ps, &s[0]) ; printf("%c %c %p %p\n", *(ps+1), s[1], ps+1, &s[1]) ; ps = s+1 ; printf("%c %c %p %p\n", *ps, s[1], ps, &s[1]) ; printf("%c %c %p %p\n", *(ps+1), s[2], ps+1, &s[2]) ; ps = &s[2] ; printf("%c %c %p %p\n", *ps, s[2], ps, &s[2]) ; printf("%c %c %p %p\n", *(ps+1), s[3], ps+1, &s[3]) ; printf("%c %c %p %p\n", s[0], *s, &s[0], s) ; printf("%c %c %p %p\n", s[2], *(s+2), &s[2], s+2) ; ps = s+1 ; printf("%s\n", ps) ; ps = s ; for(i=0;i<10;i++) printf("%d %c %c %c %p %p %p\n", i, s[i], *(ps+i), ps[i], &s[i], s+i, ps+i) ; pa = a ; printf("%d %d %p %p\n", *pa, a[0], pa, &a[0]) ; printf("%d %d %p %p\n", *(pa+1), a[1], pa+1, &a[1]) ; pa = a+1 ; printf("%d %d %p %p\n", *pa, a[1], pa, &a[1]) ; printf("%d %d %p %p\n", *(pa+1), a[2], pa+1, &a[2]) ; pa = &a[2] ; printf("%d %d %p %p\n", *pa, a[2], pa, &a[2]) ; printf("%d %d %p %p\n", *(pa+1), a[3], pa+1, &a[3]) ; printf("%d %d %p %p\n", a[0], *a, &a[0], a) ; printf("%d %d %p %p\n", a[2], *(a+2), &a[2], a+2) ; pa = a ; for(i=0;i<10;i++) printf("%d %d %d %d %p %p %p\n", i, a[i], *(pa+i), pa[i], &a[i], a+i, pa+i) ;

9 ex12-3.c /* $Id: ex12-3.c,v 1.2 2004-06-25 10:17:10+09 naito Exp $ */ /* */ #include <stdio.h> int foo_0(int) ; int foo_1(int *) ; int a=1 ; int main(int argc, char **argv) int b=2 ; printf("(main)\taddress of a = %p\n", &a) ; foo_0(a) ; printf("%d\n", a) ; foo_1(&a) ; printf("%d\n", a) ; printf("(main)\taddress of b = %p\n", &b) ; foo_0(b) ; printf("%d\n", b) ; foo_1(&b) ; printf("%d\n", b) ; int foo_0(int a) printf("(foo_0)\taddress of a = %p\n", &a) ; a += 1 ; int foo_1(int *a) printf("(foo_1)\taddress of a = %p\n", a) ; *a += 1 ;

10 ex12-4.c /* $Id: ex12-4.c,v 1.6 2004-06-30 08:00:35+09 naito Exp $ */ /* */ #include <stdio.h> #include <strings.h> #define N 11 char *_strcpy(char *, char *) ; char *strcpy(char *, const char *) ; int main(int argc, char **argv) char a[n] = "0123456789" ; char b[n], c[n], d[n], e[n] ; int i, len ; len = strlen(a) ; for(i=0;i<=len;i++) *(b+i) = *(a+i) ; i = 0 ; while((*(c+i) = *(a+i))) i += 1 ; _strcpy(d,a) ; strcpy(e,a) ; printf("a = %s\n", a) ; printf("b = %s\n", b) ; printf("c = %s\n", c) ; printf("d = %s\n", d) ; printf("e = %s\n", e) ; /*, */ /* while((*e++ = *a++)) ; */ char *_strcpy(char *t, char *s) int i = 0 ; while((*(t+i) = *(s+i))) i += 1 ; return t ; char *strcpy(char *t, const char *s) char *save=t ; while((*t++ = *s++)) ; return save ;

11 ex12-5.c /* $Id: ex12-5.c,v 1.2 2005-07-04 17:34:21+09 naito Exp $ */ /* */ #include <stdio.h> int main(int argc, char **argv) char a[] = "message" ; char *p = "message" ; int i ; printf("p = %s\n", p) ; for(i=0;*(p+i);i++) printf("%s\n", p+i) ; printf("p = %s\n", p) ; for(;*p;p++) printf("%s\n", p) ; printf("a = %s\n", a) ; for(i=0;*(a+i);i++) printf("%s\n", a+i) ; /*, */ /* for(;*a;a++) printf("%s\n", a) ; */ a[0] = M ; /* */ printf("a = %s\n", a) ; /* p[0] = M ; */

12 ex12-6.c /* $Id: ex12-6.c,v 1.2 2004-06-25 11:28:34+09 naito Exp $ */ /* */ #include <stdio.h> void swap_char(char *, char *) ; void not_swap_char(char, char) ; void swap_int(int *, int *) ; int main(int argc, char **argv) char a = a, b = b ; int n = 0x01020304, m = 0x05060708 ; not_swap_char(a,b) ; printf("a = %c, b = %c\n", a, b) ; swap_char(&a,&b) ; printf("a = %c, b = %c\n", a, b) ; swap_int(&n, &m) ; printf("n = %08x, m = %08x\n", n, m) ; /* BUG */ swap_char((char *)&n, (char *)&m) ; printf("n = %08x, m = %08x\n", n, m) ; /* */ /* swap_int((int *)&a, (int *)&b) ; */ void swap_char(char *a, char *b) char c ; c = *a ; *a = *b ; *b = c ; return ; void not_swap_char(char a, char b) char c ; c = a ; a = b ; b = c ; return ; void swap_int(int *a, int *b) int c ; c = *a ; *a = *b ; *b = c ; return ;

13 ex12-7.c /* $Id: ex12-7.c,v 1.2 2004-06-25 13:39:57+09 naito Exp $ */ /* swap */ #include <stdio.h> void swap(void *, void *, size_t size) ; int main(int argc, char **argv) char a = a, b = b ; int n = 0x01020304, m = 0x05060708 ; swap(&a,&b,sizeof(char)) ; printf("a = %c, b = %c\n", a, b) ; swap(&n,&m,sizeof(int)) ; printf("n = %08x, m = %08x\n", n, m) ; void swap(void *a, void *b, size_t size) char c ; int i=0 ; while(i<size) c = *(char *)a ; *(char *)a++ = *(char *)b ; *(char *)b++ = c ; i += 1 ; return ;

14 ex12-8.c /* $Id: ex12-8.c,v 1.3 2005-07-03 16:37:19+09 naito Exp $ */ /* */ #include <stdio.h> int main(int argc, char **argv) char **pstr ; char *str[3] ; char s0[]="string 0", s1[]="string 1", s2[]="string 2" ; char *str_array[] = "abc", "defg", "hijkl" ; int i ; str[0] = s0 ; str[1] = s1 ; str[2] = s2 ; pstr = str ; printf("%s\n", str[0]) ; printf("%s\n", str[1]) ; printf("%s\n", str[2]) ; for(i=0;i<3;i++) printf("%s\n", *(pstr+i)) ; for(i=0;i<3;i++) printf("%s\n", str_array[i]) ; for(i=0;i<argc;i++) printf("%s\n", argv[i]) ;

15 ex12-9.c /* $Id: ex12-9.c,v 1.4 2005-07-03 16:37:43+09 naito Exp $ */ /* */ #include <stdio.h> char *strchr(const char *, int) ; int main(int argc, char **argv) char s[] = "This is a test." ; char *p ; if ((p = strchr(s, i ))!= NULL) printf("%s\n", p) ; printf("%lu\n", p-s) ; else printf("not Found\n") ; if ((p = strchr(s, x ))!= NULL) printf("%s\n", p) ; printf("%lu\n", p-s) ; else printf("not Found\n") ; char *strchr(const char *s, int c) while((*s)&&(*s++!= c)) ; if (!*s) return NULL ; return (char *)(s-1) ;

16,.,,,. stdio.h, ctype.h, strings.h., exercise-12-2 exercies-12-4. exercise-12-1. int ext_gcd(int a, int b, int *x, int *y) a, b, ax + by =gcd(a, b) x, y, xy 0,. a b. exercise-12-2 year month day hour minute second, 1970 1 1 0 0 0 unsigned long., hour 24.., static int normal_year[]=31,28,31,30,31,30,31,31,30,31,30,31 ; static int leap_year[] =31,29,31,30,31,30,31,31,30,31,30,31 ; int *days_of_month=normal_year ;,. exercise-12-3 unsigned long n 1970 1 1 0 0 0, n, year month day hour minute second year, month, day, hour, minute, second., hour 24. exercise-12-4 unsigned long n 1970 1 1 0 0 0, n,. WWW MMM DD HH:MM:SS YYY, DD. 01. HH. MM. SS. YYYY. MMM. Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec. WWW. Sun Mon Tue Wed Thr Fri Sat. 1970 1 1., 24,

17 static char str[25] ;., sprintf. exercise-12-5. exercise-12-5-1 strcat exercise-12-5-2 strncat exercise-12-5-3 strncpy exercise-12-5-4 strcmp exercise-12-5-5 strncmp exercise-12-5-6 strspn exercise-12-5-7 strcspn exercise-12-5-8 strstr exercise-12-5-9 strpbrk.,.. exercise-12-6. char *strrstr(const char *s1, const char *s2) s1 s2., NULL.. exercise-12-7,. char *_strtok(char *t, const char *s, const char *d) s d, t,, s t., NULL. t.,,,.., strtok. (token),., (token decomposition),., This is a test., This, is, a, test.

18. exercise-12-8. n., 10 10.,. exercise-12-9 1024 10, 100.,, int., isspace, 10, + -, 10 isdigit.,,, 10., 10, atoi.,. exercise-12-10 10, ex-11-10 64., 64 10. 7 18. 7 20,.,.,.., 7 20,. 7 13 7 20 8 2., 8. 7 20,.,,,. 8.