(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

Size: px
Start display at page:

Download "(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"

Transcription

1 (K&R.9) ~, &,, >>, <<. (K&R 5.7) 3. (K&R 5.9). (K&R 5.) (argc argv atoi(), atof() ) 5. (K&R 7.5) (K&R 7.6) - FILE, stdin, stdout, stderr - fopen(), fclose(), getc(), putc(), fprintf(), fscanf(), (K&R.9) ~, &,, >>, << bit.c 3 int main(){ unsigned int x, r1, r, r3, r, r5; 5 6 scanf("%d", &x); 7 r1 = x & 0177; 8 r = x 0xb; 9 r3 = x & ~077; r = x << 1; 11 r5 = x >> ; 1 13 printf("x: %u\nx & 0177: %u\nx 0xb: %u\n" 1 "x & ~077: %u\nx << 1: %u\nx >> : %u\n", 15 x, r1, r, r3, r, r5); 16 return 0; 17 } % echo 19 bit x: 19 x & 0177: 1 x 0xb: 139 x & ~077: 18 x << 1: 58 x >> : 3 bit unsigned 0 8 0x 16 (K&R p.5) 15

2 3. (K&R 5.7) multiarray1.c 3 int main(){ 5 int test[][3] 6 = {{5,, 15}, {0, 00, 300}}; 7 8 int (*pt)[3] = test; 9 int i, j; 11 for(i=0; i<; i++) 1 for(j=0; j<3; j++) 13 printf("test[%d][%d] = %d at %p\n", 1 i, j, test[i][j], &test[i][j]); putchar( \n ); 17 for(i=0; i<; i++) 18 for(j=0; j<3; j++) 19 printf("*(*(test+%d)+%d) = %d at %p\n", 0 i, j, *(*(pt+i)+j), *(pt+i)+j); 1 return 0; 3 } test[0][0] = 5 at 0xbffffba0 test[0][1] = at 0xbffffba test[0][] = 15 at 0xbffffba8 test[1][0] = 0 at 0xbffffbac test[1][1] = 00 at 0xbffffbb0 test[1][] = 300 at 0xbffffbb int test[][3] *(*(test+0)+0) = 5 at 0xbffffba0 *(*(test+0)+1) = at 0xbffffba *(*(test+0)+) = 15 at 0xbffffba8 *(*(test+1)+0) = 0 at 0xbffffbac *(*(test+1)+1) = 00 at 0xbffffbb0 *(*(test+1)+) = 300 at 0xbffffbb 16

3 multiarray.c 3 int element(int array[][3], int, int); void initialize(int (*array)[3]); 5 6 int main(){ 7 8 int test[][3] 9 = { {5,, 15}, {0, 00, 300}}; int i, j; 11 1 for(i = 0; i < ; i++){ 13 for(j = 0; j < 3; j++) 1 printf("%d\t", element(test, i, j)); 15 printf("\n"); 16 } initialize(test); 19 for(i = 0; i < ; i++){ 0 for(j = 0; j < 3; j++) 1 printf("%d\t", element(test, i, j)); printf("\n"); 3 } return 0; 5 } 6 7 int element(int (*multi_array)[3], int x, int y) 8 { 9 return multi_array[x][y]; 30 } 31 3 void initialize(int multi_array[][3]) 33 { 3 int i,j; 35 for(i = 0; i < ; i++) 36 for(j = 0; j < 3; j++) 37 multi_array[i][j] = 0; 38 } f(int array[][13]) {... } f(int array[][13]) {... } f(int (*array)[13]) {... } ( : K&R p.11, p.137)

4 3.3 (K&R 5.9) pointer-marray1.c (K&R 5.9) 3 int main(){ 5 char *name[] 6 = { "Illegal month", "Jan", "Feb", "Mar" }; 7 char aname[][15] 8 = { "Illegal month", "Jan", "Feb", "Mar" }; 9 int i; 11 for(i = 0; i < ; i++) 1 printf("%s, %s (%p)\n", 13 name[i], *(name + i), name + i); 1 15 for(i = 0; i < ; i++) 16 printf("%s, %s (%p)\n", 17 aname[i], *(aname + i), aname + i); return 0; 0 } Illegal month, Illegal month (0xbffffbb0) Jan, Jan (0xbffffbb) Feb, Feb (0xbffffbb8) Mar, Mar (0xbffffbbc) Illegal month, Illegal month (0xbffffb70) Jan, Jan (0xbffffb7f) Feb, Feb (0xbffffb8e) Mar, Mar (0xbffffb9d) char *name[] ={ Illegal month, Jan, Feb, Mar name: Illegal month 0 Jan 0 Feb 0 Mar 0 aname[][15] ={ Illegal month, Jan, Feb, Mar aname: Illegal month 0 Jan 0 Feb 0 Mar pointer-marray.c 3 int main(){ 5 char *name[] 6 = { "Illegal month", "Jan", "Feb", "Mar" }; 7 int i; char **ip; 8 9 ip = name; for(i = 0; i < ; i++) 11 printf("%s\n", *ip++); 1 13 return 0; 1 } ip: name: Illegal month 0 Jan 0 Feb 0 Mar 0 Illegal month Jan Feb Mar 18

5 3. (K&R 5.) argument1.c 3 int main(int argc, char *argv[]) { 5 int i; 6 7 for(i = 0; i < argc; i++) 8 printf("argv[%d] = %s\n", i, argv[i]); 9 printf("\n"); 11 for(i = 1; i < argc; i++) 1 printf("%s%s", argv[i], (i < argc -1)? " " : ""); 13 printf("\n"); 1 15 for(i = 1; argv[i]!= NULL; i++) 16 printf("%s%s", argv[i], (i < argc -1)? " " : ""); 17 printf("\n"); while(--argc > 0) 0 printf((argc > 1)? "%s " : "%s", *++argv); 1 printf("\n"); return 0; 3 }? K&R p.6 (null pointer) K&R p.15 (0) NULL % argument1 abc ABC argv[0] = argument1 argv[1] = abc argv[] = ABC abc ABC abc ABC abc ABC % echo hello, world argv: 0 (NULL) echo 0 hello, 0 world 0 argument.c #include <stdlib.h> 3 #include <math.h> /* -lm may be required. */ 5 int main(int argc, char *argv[]){ 6 int x, y; 7 8 if (argc!= 3) 9 exit(1); x = atoi(argv[1]); y = atoi(argv[]); 11 printf("%d to the %dth power = %.0f\n", 1 x, y, pow((double) x, (double) y)); 13 return 0; 1 } (K&R p.56) ( ) % argument 8 to the 8th power = 56 19

6 3.5 (K&R 7.5) (K&R 7.6) cat1.c (K&R 7.5 p.197. ) 1 /* K&R Chapter 7.5 */ #include <stdio.h> 3 /* cat: version 1 */ 5 6 int main(int argc, char *argv[]) 7 { 8 FILE *fp; /* file pointer */ 9 void filecopy(file *, FILE *); 11 if (argc == 1) 1 filecopy(stdin, stdout); 13 else 1 while (--argc > 0) 15 if ((fp = fopen(*++argv, "r")) == NULL) { 16 printf("cat: can t open %s\n", *argv); 17 return 1; 18 } else { 19 filecopy(fp, stdout); 0 fclose(fp); 1 } return 0; 3 } 5 /* filecopy */ 6 void filecopy(file *ifp, FILE *ofp) 7 { 8 int c; 9 while ((c = getc(ifp))!= EOF) 30 putc(c, ofp); 31 } stdin stdout getc(stdin) getchar() putc(c, stdout) putchar(c) 0

7 cat.c (K&R 7.6 p.199) 1 /* K&R Chapter 7.6 */ #include <stdio.h> 3 #include <stdlib.h> 5 /* cat: version */ 6 7 int main(int argc, char *argv[]) 8 { 9 FILE *fp; /* file pointer */ void filecopy(file *, FILE *); 11 char *prog = argv[0]; 1 13 if (argc == 1) 1 filecopy(stdin, stdout); 15 else 16 while (--argc > 0) 17 if ((fp = fopen(*++argv, "r")) == NULL) { 18 fprintf(stderr, "%s: can t open %s\n", 19 prog, *argv); 0 exit(1); 1 } else { filecopy(fp, stdout); 3 fclose(fp); } 5 if (ferror(stdout)) { 6 fprintf(stderr, 7 "%s: error writing stdout\n", prog); 8 exit(); 9 } 30 exit(0); 31 } 3 33 /* filecopy */ 3 void filecopy(file *ifp, FILE *ofp) 35 { 36 int c; 37 while ((c = getc(ifp))!= EOF) 38 putc(c, ofp); 39 } stderr ferror(fp) fp - ( r ) ( w ) ( ) - 1 fgets() (K&R 7.7, p.00) ( ) - (K&R B3, p.313) strtok() ( strtok r() ) sscanf(), sprintf() K&R.1,. 1

8 1. (K&R.9) ~, &,, >>, <<. (K&R.11.3) (#ifdef, #if, #endif) 3. (K&R.) (K&R.6). separate compilation) (K&R.5) malloc(), strdup() struct.1 ~, &,, >>, << getbits.c (K&R.9, p.61) #include <stdlib.h> 3 void error_message(char *); unsigned getbits(unsigned, int, int); 5 6 int main(int argc, char *argv[]) 7 { 8 unsigned int x; 9 int position, n; 11 if (argc!= ) { 1 fprintf(stderr, "usage: %s x p n\n", argv[0]); 13 exit(1); 1 } x = atoi(*++argv); 17 position = atoi(*++argv); 18 n = atoi(*++argv); 19 printf("result: %u\n", getbits(x, position, n)); 0 return 0; 1 } 3 /* getbits: get n bits from position p */ unsigned getbits(unsigned x, int p, int n) 5 { 6 return (x >> (p+1-n)) & ~(~0 << n); 7 } x p n x p () n 0

9 % getbits result: 1 % getbits result: 0 % getbits result: 1 % getbits result: 7 p x % getbits >> (x >> (p+1-n)) & ~(~0 << n) n ~ << ~ & (K&R.11.3, p.111) - #ifdef, #if, #endif, preprocessing1.c #define DEBUG 3 int main() 5 { 6 #ifdef DEBUG 7 printf("debug mode \n"); 8 #else 9 printf("normal mode \n"); #endif 11 return 0; 1 } preprocessing.c /* #define DEBUG */ 3 int main() 5 { 6 #ifdef DEBUG 7 printf("debug mode \n"); 8 #else 9 printf("normal mode \n"); #endif 11 return 0; 1 } cc -DDEBUG DEBUG cc -E ( ) 3

10 .3 (K&R.) (K&R.6) main1.c 1 void init(); 3 int main() { 5 init(); 6 return 0; 7 } init1.c 1 void init() {} init.c 1 static void init() {} main.c extern int value; 3 int main() 5 { 6 printf("%d\n", value); 7 return 0; 8 } value1.c 1 int value = 1; value.c 1 static int value = 1; static1.c #define ITERATIONS 0 3 int count(void); 5 int main() 6 { 7 int i; 8 for(i = 0; i < ITERATIONS - 1; i++) 9 count(); printf("%d\n", count()); 11 return 0; 1 } 13 1 int count(void) 15 { 16 static int x = 0; 17 return ++x; 18 } % gcc -c main1.c -Wall % gcc -c init1.c -Wall % gcc main1.o init1.o -Wall -o test1 % gcc -c init.c -Wall init.c:1: warning: init defined but not used % gcc main1.o init.o -Wall -o test Undefined first referenced symbol in file init main1.o ld: fatal: Symbol referencing errors. No output written to test collect: ld returned 1 exit status % gcc -c main.c -Wall % gcc -c value1.c -Wall % gcc main.o value1.o -Wall -o test3 % test3 1 % gcc -c value.c -Wall value.c:1: warning: value defined but not used % gcc main.o value.o -Wall -o test Undefined first referenced symbol in file value main.o ld: fatal: Symbol referencing errors. No output written to test collect: ld returned 1 exit status % gcc static1.c -o static1 -Wall % static1 0 K&R p.1. static static

11 . separate compilation (K&R.5) filecopy.h 1 void filecopy(file *input_file, FILE *ouput_file); filecopy.c #include "filecopy.h" 3 /* filecopy */ 5 void filecopy(file *ifp, FILE *ofp) 6 { 7 int c; 8 while ((c = getc(ifp))!= EOF) 9 putc(c, ofp); } cat main.c #include <stdlib.h> 3 #include "filecopy.h" 5 int main(int argc, char *argv[]) 6 { 7 FILE *fp; /* file pointer */ 8 char *prog = argv[0]; 9 if (argc == 1) 11 filecopy(stdin, stdout); 1 else 13 while (--argc > 0) 1 if ((fp = fopen(*++argv, "r")) == NULL) { 15 fprintf(stderr, "%s: can t open %s\n", 16 prog, *argv); 17 exit(1); 18 } else { 19 filecopy(fp, stdout); 0 fclose(fp); 1 } if (ferror(stdout)) { 3 fprintf(stderr, "%s: error writing stdout\n", prog); 5 exit(); 6 } 7 exit(0); 8 } - (#define) - extern - - ソースソースコードソースコードコードコンパイル, アセンブル オブジェクトオブジェクトファイルオブジェクトファイルファイル リンク 実行形式 ライブラリ % ls cat_main.c filecopy.c filecopy.h % cc -c filecopy.c % cc -c cat_main.c % ls cat_main.c cat_main.o filecopy.c filecopy.h filecopy.o % cc filecopy.o cat_main.o -o cat1 % ls cat1* cat_main.c cat_main.o filecopy.c filecopy.h filecopy.o 5

12 .5 cp1.c #include <stdlib.h> 3 #include "filecopy.h" 5 int main(int argc, char *argv[]) 6 { 7 FILE *fp_in, *fp_out; /* file pointers */ 8 void filecopy(file *, FILE *); 9 char *prog = argv[0]; 11 if (argc!= 3) { 1 fprintf(stderr, 13 "usage: %s input_file output_file\n", prog); 1 exit(1); 15 } if ((fp_in = fopen(*++argv, "r")) == NULL) { 18 fprintf(stderr, "%s: can t open %s\n", 19 prog, *argv); 0 exit(); 1 } 3 if ((fp_out = fopen(*++argv, "w")) == NULL) { fprintf(stderr, "%s: can t create %s\n", 5 prog, *argv); 6 exit(); 7 } 8 9 filecopy(fp_in, fp_out); 30 fclose(fp_in); 31 3 if (ferror(fp_out)) { 33 fprintf(stderr, 3 "%s: error writing %s\n", prog, *argv); 35 exit(3); 36 } 37 fclose(fp_out); 38 exit(0); 39 } % ls cp1* textsample % cat textsample Most wild animals remain fertile until they die, or until close to that time. % cp1 textsample tmp % ls cp1* textsample tmp % cat tmp Most wild animals remain fertile until they die, or until close to that time. 6

13 .6 get integers.c 3 int main(){ int v, n; 5 char c; 6 7 while((n = scanf("%d", &v))!= EOF) 8 if (n == 1) 9 printf("%d\n", v); else { 11 scanf("%c", &c); 1 printf("%c\n", c); 13 } 1 return 0; 15 } scanf() process line.h 1 void process_line(char *); get each line.c #include <stdlib.h> 3 #include <string.h> #include "process_line.h" 5 #define MAX_LINE int main(void){ 8 char line[max_line]; 9 while(fgets(line, sizeof(line), stdin)!= NULL) { 11 if (line[strlen(line)-1]!= \n ) { 1 fprintf(stderr, "too long line\n"); 13 exit(1); 1 } 15 process_line(line); 16 } 17 exit(0); 18 } process line1.c #include <stdlib.h> 3 #include <string.h> #include "process_line.h" 5 6 void process_line(char *p) 7 { 8 if (!strcmp(p, "OWARI\n")) 9 exit(0); 11 printf("%s", p); 1 } gets() fgets() scanf( %s, str) fgets() ( \n ) strlen(s) s \0 (K&R p.8) strcmp() 0 (K&R p.0) 7

14 process line.c #include <stdlib.h> 3 #include <string.h> #include "process_line.h" 5 #define DELIM " \t\n\":;.,!?" 6 7 void process_line(char *str) 8 { 9 char *tp, *p; 11 tp = strtok_r( str, DELIM, &p); 1 while (tp!= NULL) { 13 puts(tp); 1 tp = strtok_r( NULL, DELIM, &p); 15 } 16 } process line3.c #include <string.h> 3 #include "process_line.h" #define DELIM " \t\n\":;.,!?" 5 #define DEBUG 6 7 void process_line(char *str) 8 { 9 char *tp, *p; 11 #ifdef DEBUG 1 fprintf(stderr, "str: %p : %s\n", str, str); 13 #endif 1 15 tp = strtok_r(str, DELIM, &p); #ifdef DEBUG 18 fflush(stdout); 19 fprintf(stderr, "tp : %p : %s\n", tp, tp); 0 fprintf(stderr, "p : %p : %s\n", p, p); 1 #endif 3 while (tp!= NULL) { puts(tp); 5 tp = strtok_r(null, DELIM, &p); 6 7 #ifdef DEBUG 8 fflush(stdout); 9 fprintf(stderr, "tp : %p : %s\n", tp, tp); 30 fprintf(stderr, "p : %p : %s\n", p, p); 31 #endif 3 } 33 } strtok r(str, delim, &p) s delim (, token) p s NULL p str tp p R u m o r h a s i t n 0 str tp p R u m o r 0 h a s i t n 0 str tp p R u m o r 0 h a s 0 i t n 0 str tp p R u m o r 0 h a s 0 i t 0 0 % a.out > tmp Rumor has it str: 0xbfbfe980 : Rumor has it tp : 0xbfbfe980 : Rumor p : 0xbfbfe986 : has it tp : 0xbfbfe986 : has p : 0xbfbfe98a : it tp : 0xbfbfe98b : it p : 0xbfbfe98e : tp : 0x0 : (null) p : 0x0 : (null) % cat tmp Rumor has it 8

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

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n 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

More information

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

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B A/B (2018/10/19) Ver. 1.0 kurino@math.cst.nihon-u.ac.jp http://edu-gw2.math.cst.nihon-u.ac.jp/ kurino/2018/soft/soft.html 2018 10 19 A/B 1 2018 10 19 2 1 1 1.1 OHP.................................... 1

More information

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

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) 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

More information

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

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 18 C ( ) 1 1 1.1 hello world.c 5 printf("hello World\n"); 6 } [ ] [ ] #include % cc hello_world.c %./a.out Hello World [a.out ] % cc hello_world.c -o hello_world [ ( ) ] (K&R 4.1.1) #include

More information

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

新・明解C言語 ポインタ完全攻略 2 1-1 1-1 /* 1-1 */ 1 int n = 100; int *p = &n; printf(" n %d\n", n); /* n int */ printf("*&n %d\n", *&n); /* *&n int */ printf(" p %p\n", p); /* p int * */ printf("&*p %p\n", &*p); /* &*p int * */ printf("sizeof(n)

More information

gengo1-12

gengo1-12 外部変数 関数の外で定義される変数を外部変数 ( 大域変数 ) と呼ぶ 外部変数のスコープは広域的 ( プログラム全体 ) 全ての関数で参照可能 int a=10; double x=3.14159; printf( a = %d\n, a); sample(); printf( %f\n, x); void sample(void) printf( %f\n, x); x += 1.0; 外部変数

More information

超初心者用

超初心者用 3 1999 10 13 1. 2. hello.c printf( Hello, world! n ); cc hello.c a.out./a.out Hello, world printf( Hello, world! n ); 2 Hello, world printf n printf 3. ( ) int num; num = 100; num 100 100 num int num num

More information

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

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 II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C 1 6 9 1 main main 1 NULL NULL 1 15 23 25 48 26 30 32 36 38 43 45 47 50 52 for 2 (a) 2 2 1 Yacc 2 (b) 2 3 yytext tmp2 ("") tmp2->next->word tmp2 yytext tmp2->next->word

More information

新版明解C言語 実践編

新版明解C言語 実践編 2 List - "max.h" a, b max List - max "max.h" #define max(a, b) ((a) > (b)? (a) : (b)) max List -2 List -2 max #include "max.h" int x, y; printf("x"); printf("y"); scanf("%d", &x); scanf("%d", &y); printf("max(x,

More information

ex14.dvi

ex14.dvi 1,, 0, b (b b 2 b ) n k n = n j b j, (0 n j b 1), n =(n k n k 1...n 1 n 0 ) b, n j j j +1, 0,...,b 1 (digit). b b, n b 1 ñ, ñ = k (b 1 n j )b j b N, n b n, n = b N n, n =ñ+1 b N, n m n + m (mod b N ),

More information

gengo1-12

gengo1-12 外部変数 関数の外で定義される変数を外部変数 ( 大域変数 ) と呼ぶ 外部変数のスコープは広域的 ( プログラム全体 ) 全ての関数で参照可能 int a=10; double x=3.14159; printf( a = %d\n, a); sample(); printf( %f\n, x); void sample(void) printf( %f\n, x); x += 1.0; 外部変数

More information

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

filea fileb fp = fopen(a, r); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen(b, r); while(fgets(line, BUFSIZ, fp)) {... fclose I117 9 2 School of Information Science, Japan Advanced Institute of Science and Technology file"a" file"b" fp = fopen("a", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen("b", "r"); while(fgets(line,

More information

新・明解C言語 実践編

新・明解C言語 実践編 第 1 章 見 21 1-1 見えないエラー 見 List 1-1 "max2x1.h" a, b max2 List 1-1 chap01/max2x1.h max2 "max2x1.h" #define max2(a, b) ((a) > (b)? (a) : (b)) max2 List 1-2 List 1-2 chap01/max2x1test.c max2 #include

More information

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

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

More information

double float

double float 2015 3 13 1 2 2 3 2.1.......................... 3 2.2............................. 3 3 4 3.1............................... 4 3.2 double float......................... 5 3.3 main.......................

More information

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

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 II 8 2003 11 12 1 6 ( ) 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 Daisuke 8 =>. 73 Daisuke 35 Hiroshi 64 Ichiro 87 Junko

More information

ohp03.dvi

ohp03.dvi 19 3 ( ) 2019.4.20 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void int main(int argc, char *argv[]) {... 2 (2) argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0

More information

計算機プログラミング

計算機プログラミング プログラミング言語 C 第 8 講 システム標準関数 ( 入出力関数 ) システム標準関数 システムに備え付けの関数 例 ) printf( ); scanf( ); 標準出力関数 標準入力関数 A. 入出力用の関数 高水準入出力関数 高水準言語 (OS に依存しない ) 低水準入出力関数 機械語レベル (OS に依存 ) B. それ以外の関数 引数と関数の型 ( 戻り値 ) に注目しましょう 例

More information

橡Pro PDF

橡Pro PDF 1 void main( ) char c; /* int c; */ int sum=0; while ((c = getchar())!= EOF) if(isdigit(c) ) sum += (c-'0'); printf("%d\n", sum); main()int i,sum=0; for(i=0;i

More information

1.ppt

1.ppt /* * Program name: hello.c */ #include int main() { printf( hello, world\n ); return 0; /* * Program name: Hello.java */ import java.io.*; class Hello { public static void main(string[] arg)

More information

tuat1.dvi

tuat1.dvi ( 1 ) http://ist.ksc.kwansei.ac.jp/ tutimura/ 2012 6 23 ( 1 ) 1 / 58 C ( 1 ) 2 / 58 2008 9 2002 2005 T E X ptetex3, ptexlive pt E X UTF-8 xdvi-jp 3 ( 1 ) 3 / 58 ( 1 ) 4 / 58 C,... ( 1 ) 5 / 58 6/23( )

More information

r07.dvi

r07.dvi 19 7 ( ) 2019.4.20 1 1.1 (data structure ( (dynamic data structure 1 malloc C free C (garbage collection GC C GC(conservative GC 2 1.2 data next p 3 5 7 9 p 3 5 7 9 p 3 5 7 9 1 1: (single linked list 1

More information

スライド タイトルなし

スライド タイトルなし ファイル入出力 (2) これまでのおさらい ( 入出力 ) これまでの入出力は 入力 scanf 出力 printf キーボードと画面 ( 端末 ) scanf/printf は 書式つき入出力 フォーマットを指定する 標準入出力を対象とする 何もしなければ 標準入出力は キーボードと画面 ストリームという考え方 ストリーム (stream) = データの列 キーボードから打つ文字列 画面に出力される文字列

More information

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

Microsoft PowerPoint - CproNt11.ppt [互換モード] 第 11 章入出力関数とライブラリ関数 CPro:11-01 概要 getchar putchar gets puts scanf printf strcat strcmp strcpy strlen atoi atof sprint sscanf 11.1 コンソール入出力関数 11-02 入力 出力 getchar putchar 一文字 gets puts 文字列 ( 一行 ) scanf printf

More information

ohp07.dvi

ohp07.dvi 19 7 ( ) 2019.4.20 1 (data structure) ( ) (dynamic data structure) 1 malloc C free 1 (static data structure) 2 (2) C (garbage collection GC) C GC(conservative GC) 2 2 conservative GC 3 data next p 3 5

More information

comment.dvi

comment.dvi ( ) (sample1.c) (sample1.c) 2 2 Nearest Neighbor 1 (2D-class1.dat) 2 (2D-class2.dat) (2D-test.dat) 3 Nearest Neighbor Nearest Neighbor ( 1) 2 1: NN 1 (sample1.c) /* -----------------------------------------------------------------

More information

r03.dvi

r03.dvi 19 ( ) 019.4.0 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void... argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0 a a \0 b b b \0 c c c \0 1: // argdemo1.c ---

More information

ex12.dvi

ex12.dvi 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

More information

卒 業 研 究 報 告.PDF

卒 業 研 究 報 告.PDF C 13 2 9 1 1-1. 1-2. 2 2-1. 2-2. 2-3. 2-4. 3 3-1. 3-2. 3-3. 3-4. 3-5. 3-5-1. 3-5-2. 3-6. 3-6-1. 3-6-2. 4 5 6 7-1 - 1 1 1-1. 1-2. ++ Lisp Pascal Java Purl HTML Windows - 2-2 2 2-1. 1972 D.M. (Dennis M Ritchie)

More information

gengo1-12

gengo1-12 外部変数 関数の外で定義される変数を外部変数 ( 大域変数 ) と呼ぶ 外部変数のスコープは広域的 ( プログラム全体 ) 全ての関数で参照可能 int a=10; double x=3.14159; printf( a = %d\n, a); sample(); printf( %f\n, x); void sample(void) printf( %f\n, x); x += 1.0; 外部変数

More information

untitled

untitled II yacc 005 : 1, 1 1 1 %{ int lineno=0; 3 int wordno=0; 4 int charno=0; 5 6 %} 7 8 %% 9 [ \t]+ { charno+=strlen(yytext); } 10 "\n" { lineno++; charno++; } 11 [^ \t\n]+ { wordno++; charno+=strlen(yytext);}

More information

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

Microsoft Word - C.....u.K...doc C uwêííôöðöõ Ð C ÔÖÐÖÕ ÐÊÉÌÊ C ÔÖÐÖÕÊ C ÔÖÐÖÕÊ Ç Ê Æ ~ if eíè ~ for ÒÑÒ ÌÆÊÉÉÊ ~ switch ÉeÍÈ ~ while ÒÑÒ ÊÍÍÔÖÐÖÕÊ ~ 1 C ÔÖÐÖÕ ÐÊÉÌÊ uê~ ÏÒÏÑ Ð ÓÏÖ CUI Ô ÑÊ ÏÒÏÑ ÔÖÐÖÕÎ d ÈÍÉÇÊ ÆÒ Ö ÒÐÑÒ ÊÔÎÏÖÎ d ÉÇÍÊ

More information

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

Taro-ファイル処理(公開版).jtd ファイル処理 0. 目次 1. はじめに 2. ファイル内容の表示 3. ファイル内容の複写 3. 1 文字単位 3. 2 行単位 4. 書式付き入出力 5. 文字配列への入出力 6. 課題 6. 1 課題 1 ( ファイル圧縮 復元 ) - 1 - 1. はじめに ファイル処理プログラムの形は次のようになる #include main() { FILE *fp1,*fp2; ファイルポインタの宣言

More information

joho07-1.ppt

joho07-1.ppt 0xbffffc5c 0xbffffc60 xxxxxxxx xxxxxxxx 00001010 00000000 00000000 00000000 01100011 00000000 00000000 00000000 xxxxxxxx x y 2 func1 func2 double func1(double y) { y = y + 5.0; return y; } double func2(double*

More information

ohp08.dvi

ohp08.dvi 19 8 ( ) 2019.4.20 1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: 2 (2) NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( 2) 3 (3) head cur tail head cur prev data

More information

memo

memo 数理情報工学演習第一 C プログラミング演習 ( 第 5 回 ) 2015/05/11 DEPARTMENT OF MATHEMATICAL INFORMATICS 1 今日の内容 : プロトタイプ宣言 ヘッダーファイル, プログラムの分割 課題 : 疎行列 2 プロトタイプ宣言 3 C 言語では, 関数や変数は使用する前 ( ソースの上のほう ) に定義されている必要がある. double sub(int

More information

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

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 C/C++ 2007 6 18 1 C STL(1) 2 1.1............................................... 2 1.2 stdio................................................ 3 1.3.......................................... 10 2 11 2.1 sizeof......................................

More information

r08.dvi

r08.dvi 19 8 ( ) 019.4.0 1 1.1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( ) 1 next 1 prev 1 head cur tail head cur prev

More information

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

第5回お試しアカウント付き並列プログラミング講習会 qstat -l ID (qstat -f) qscript ID BATCH REQUEST: 253443.batch1 Name: test.sh Owner: uid=32637, gid=30123 Priority: 63 State: 1(RUNNING) Created at: Tue Jun 30 05:36:24 2009 Started at: Tue Jun 30 05:36:27

More information

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

Microsoft Word - Cプログラミング演習(12) 第 12 回 (7/9) 4. いくつかのトピック (5)main 関数の引数を利用したファイル処理 main 関数は, 起動する環境から引数を受け取ることができる 例えば 次に示すように,main 関数に引数を用いたプログラムを作成する 01 /* sample */ 02 /* main 関数の引数 */ 03 #include 04 05 main(int argc, char

More information

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 : 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)* ( 2016 2016 07 28 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF : 11011 N N 0 N N 11 1001 N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) 1100100 (2) 1111011 (3) 1110010 (4) 1001011

More information

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

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou 1 1.1 C 2 1 double a[ ][ ]; 1 3x3 0 1 3x3 ( ) 0.240 0.143 0.339 0.191 0.341 0.477 0.412 0.003 0.921 1.2 malloc() 2 double *a[ ]; double 1 malloc() double 1 malloc() free() 3 #include #include

More information

Microsoft Word - 06

Microsoft Word - 06 平成 24 年度講義 アルゴリズムとデータ構造 第 6 回ファイル入出力 担当 : 富井尚志 (tommy@ynu.ac.jp) 第 6 回 ファイル入出力 前回 ( 第 5 回 ) 配列を扱うアルゴリズム (2) とポインタ の復習 集合を扱う 集合の表現, 配列を使った表現, 要素の列 を 集合 にする, 要素, 積, 和, 差 文字列 C 言語における文字列, 文字列を扱うプログラム 計算機の記憶とポインタ

More information

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

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) * * 2015 2015 07 30 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 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) +

More information

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

Cプログラミング1(再) 第2回 C プログラミング 1( 再 ) 第 2 回 講義では Cプログラミングの基本を学び演習では やや実践的なプログラミングを通して学ぶ 1 前回のレポートから 前回の宿題 数あてゲーム の説明において 次のように書いていたものがいた : これはコンピュータがランダムに設定した数字を人間が当てるゲームである この説明でどこかおかしなところはないだろうか? 2 コンピュータの用語と日常的な用語の違い 物理において

More information

02: 変数と標準入出力

02: 変数と標準入出力 C プログラミング入門 基幹 7 ( 水 5) 1 12: コマンドライン引数 Linux にログインし 以下の講義ページを開いておくこと http://www-it.sci.waseda.ac.jp/teachers/w48369 2/CPR1/ 2017-07-05 まとめ : ポインタを使った処理 2 内容呼び出し元の変数を書き換える文字列を渡す 配列を渡すファイルポインタ複数の値を返す大きな領域を確保する

More information

C言語入門

C言語入門 1 C 言語入門 第 7 週 プログラミング言語 Ⅰ( 実習を含む ), 計算機言語 Ⅰ 計算機言語演習 Ⅰ, 情報処理言語 Ⅰ( 実習を含む ) 2 吐き出し法 ( ガウスの消去法 ) のピボッティング 前回の復習 3 連立一次方程式を行列で計算する 吐き出し法 ( ガウスの消去法 ) ステップ 1: 前進消去 ( 上三角行列の作成 ) gaussian_elimination1.c // step1

More information

untitled

untitled C -1 - -2 - concept lecture keywords FILE, fopen, fclose, fscanf, fprintf, EOF, r w a, typedef gifts.dat Yt JZK-3 Jizake tsumeawase 45 BSP-15 Body soap set 3 BT-2 Bath towel set 25 TEA-2 Koutya

More information

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

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1 I117 II I117 PROGRAMMING PRACTICE II 2 MEMORY MANAGEMENT 2 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu@jaist.ac.jp / SCHEDULE 1. 2011/06/07(Tue) / Basic of Programming

More information

lexex.dvi

lexex.dvi (2018, c ) http://istksckwanseiacjp/ ishiura/cpl/ 4 41 1 mini-c lexc,, 2 testlexc, lexc mini-c 1 ( ) mini-c ( ) (int, char, if, else, while, return 6 ) ( ) (+, -, *, /, %, &, =, ==,!=, >, >=,

More information

C

C C 1 2 1.1........................... 2 1.2........................ 2 1.3 make................................................ 3 1.4....................................... 5 1.4.1 strip................................................

More information

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

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include 1 1.1 C 2 1 double a[ ][ ]; 1 3x3 0 1 3x3 ( ) 0.240 0.143 0.339 0.191 0.341 0.477 0.412 0.003 0.921 1.2 malloc() malloc 2 #include #include #include enum LENGTH = 10 ; int

More information

slide4.pptx

slide4.pptx ソフトウェア工学入門 第 4 回ライブラリ関数 ライブラリ関数 stdio stdio : 標準入出力ライブラリ カーネルレベルのストリームに API を追加し インタフェースを提供する カーネル fd read(2) write(2) stdio バッファ BUFSIZ プログラム BUFSIZ ごと 小さい単位 バッファ : 一時的にデータを保存しておく場所のことバッファリング : バッファを経由してデータをやり取りすること

More information

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

‚æ2›ñ C„¾„ê‡Ìš| I 8 10 10 I ( 6 ) 10 10 1 / 23 1 C ( ) getchar(), gets(), scanf() ( ) putchar(), puts(), printf() 1 getchar(), putchar() 1 I ( 6 ) 10 10 2 / 23 1 (getchar 1 1) 1 #include 2 void main(void){ 3 int

More information

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

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D 6 2019 5 14 6.1 Minimum C....................... 6 1 6.2....................................... 6 7 6.1 Minimum C Minimum C BNF T okenseq W hite Any Digit ::= 0 1 2... 9. Number ::= Digit Digit. Alphabet

More information

XMPによる並列化実装2

XMPによる並列化実装2 2 3 C Fortran Exercise 1 Exercise 2 Serial init.c init.f90 XMP xmp_init.c xmp_init.f90 Serial laplace.c laplace.f90 XMP xmp_laplace.c xmp_laplace.f90 #include int a[10]; program init integer

More information

Ⅰ Report#1 Report#1 printf() /* Program : hello.c Student-ID : 095740C Author UpDate Comment */ #include int main(){ : Yuhi,TOMARI : 2009/04/28(Thu) : Used Easy Function printf() 10 printf("hello,

More information

program.dvi

program.dvi 2001.06.19 1 programming semi ver.1.0 2001.06.19 1 GA SA 2 A 2.1 valuename = value value name = valuename # ; Fig. 1 #-----GA parameter popsize = 200 mutation rate = 0.01 crossover rate = 1.0 generation

More information

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

:30 12:00 I. I VI II. III. IV. a d V. VI 2017 2017 08 03 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF X [ S ] a S S ; X X X, S [, a, ], ; BNF X (parse tree) (1) [a;a] (2) [[a]] (3) [a;[a]] (4) [[a];a] : [a] X 2 222222

More information

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

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó  ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡ (2018) 2018 5 24 ( ) while ( ) do while ( ); for ( ; ; ) while int i = 0; while (i < 100) { printf("i = %3d\n", i); i++; while int i = 0; i while (i < 100) { printf("i = %3d\n", i); i++; while int i =

More information

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

/* 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 http://www7.bpe.es.osaka-u.ac.jp/~kota/classes/jse.html kota@fbs.osaka-u.ac.jp /* do-while */ #include #include int main(void) double val1, val2, arith_mean, geo_mean; printf( \n );

More information

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

:30 12:00 I. I VI II. III. IV. a d V. VI 2018 2018 08 02 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF N N y N x N xy yx : yxxyxy N N x, y N (parse tree) (1) yxyyx (2) xyxyxy (3) yxxyxyy (4) yxxxyxxy N y N x N yx

More information

PowerPoint Presentation

PowerPoint Presentation p.130 p.198 p.208 2 double weight[num]; double min, max; min = max = weight[0]; for( i= 1; i i < NUM; i++ ) ) if if ( weight[i] > max ) max = weight[i]: if if ( weight[i] < min ) min = weight[i]: weight

More information

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション 構造体 (struct) 構造体の宣言 typedef 宣言 配列では 複数のデータをひとまとまりにして操作することが出来る しかし それぞれのデータは同じ型 ( 例えば整数 あるいは浮動小数点数 ) 出なければならない 型の違うデータをひとまとまりにして扱う方法に 構造体がある 構造体 文文文文名前字 ( 文字列字字 ) 字 整数学籍番号 ( 整数 ) 身長 ( 浮動小数点数 ) 文字 配列 3

More information

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

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

More information

02: 変数と標準入出力

02: 変数と標準入出力 C プログラミング入門 基幹 7 ( 水 5) 12: コマンドライン引数 Linux にログインし 以下の講義ページを開いておくこと http://www-it.sci.waseda.ac.jp/ teachers/w483692/cpr1/ 2016-06-29 1 まとめ : ポインタを使った処理 内容呼び出し元の変数を書き換える文字列を渡す 配列を渡すファイルポインタ複数の値を返す大きな領域を確保する

More information

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

debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology I117 28 School of Information Science, Japan Advanced Institute of Science and Technology debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology 2008 1-2 1 a) b)

More information

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

[1] #include<stdio.h> main() { printf(hello, world.); return 0; } (G1) int long int float ± ± [1] #include printf("hello, world."); (G1) int -32768 32767 long int -2147483648 2147483647 float ±3.4 10 38 ±3.4 10 38 double ±1.7 10 308 ±1.7 10 308 char [2] #include int a, b, c, d,

More information

slide5.pptx

slide5.pptx ソフトウェア工学入門 第 5 回コマンド作成 1 head コマンド作成 1 早速ですが 次のプログラムを head.c という名前で作成してください #include #include static void do_head(file *f, long nlines); int main(int argc, char *argv[]) { if (argc!=

More information

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

第7章 有限要素法のプログラミング April 3, 2019 1 / 34 7.1 ( ) 2 Poisson 2 / 34 7.2 femfp.c [1] main( ) input( ) assem( ) ecm( ) f( ) solve( ) gs { solve( ) output( ) 3 / 34 7.3 fopen() #include FILE *fopen(char *fname, char

More information

tuat2.dvi

tuat2.dvi ( 2 ) http://ist.ksc.kwansei.ac.jp/ tutimura/ 2012 7 7 ( 2 ) 1 / 54 (1) (2) (?) (1) (2) 2 ( 2 ) 2 / 54 1. 30 2. 2012 6 30 25 OS ( 2 ) 3 / 54 10 20 1993 1996 2000 2003 = 30 ( 2 ) 4 / 54 1 2 2 ( 2 ) 5 /

More information

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

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU 1. 1.1. 1.2. 1 PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU 2. 2.1. 2 1 2 C a b N: PC BC c 3C ac b 3 4 a F7 b Y c 6 5 a ctrl+f5) 4 2.2. main 2.3. main 2.4. 3 4 5 6 7 printf printf

More information

+ +

+ + + + 2 1 1 1.1................................ 1 1.2........................... 2 1.3............................. 2 1.4 ( ).................. 2 1.5........................ 3 1.6...................... 3

More information

memo

memo 数理情報工学演習第一 C ( 第 8 回 ) 206/06/3 DEPARTMENT OF MATHEMATICAL INFORMATICS 今日の内容 : プロトタイプ宣言 ヘッダーファイル, プログラムの分割 プライオリティキュー ヒープ 課題 : ヒープソート 2 プロトタイプ宣言 C 言語では, 関数や変数は使用する前 ( ソースの上のほう ) に定義されている必要がある. double sub(int

More information

file:///D|/C言語の擬似クラス.txt

file:///D|/C言語の擬似クラス.txt 愛知障害者職業能力開発校 システム設計科 修了研究発表会報告書 題名 : C 言語の擬似クラス あらまし : C 言語でクラスを作れるという噂の真偽を確かめるために思考錯誤した まえがき : VC++ や Java その他オブジェクト指向の言語にはクラスが存在して クラスはオブジェクトの設計図である 手法 : C++ のクラスを解析して C++ のクラスを作成して C 言語に翻訳する class struct

More information

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

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 I 4 003 4 30 1 ASCII ( ) 0 17 0 NUL 16 DLE SP 0 @ P 3 48 64 80 96 11 p 1 SOH 17 DC1! 1 A Q a 33 49 65 81 97 113 q STX 18 DC " B R b 34 50 66 8 98 114 r 3 ETX 19 DC3 # 3 C S c 35 51 67 83 99 115 s 4 EOT

More information

Microsoft Word - cpro_m_13.doc

Microsoft Word - cpro_m_13.doc 第 13 章ファイル入出力 問題 13-1 ファイルのアクセスに関する次の記述中の (1)~(8) にあてはまる適切な字句を解答群 から選び, 解答欄に記号で記入しなさい ファイルを扱う場合, まず使用するファイルをfopen 関数でオープンする この関数 には引数が二つあり, 最初の引数には (1) が格納されている領域へのポインタ を指定するが, このポインタは (2) 型のポインタである また,2

More information

1 $ cat aboutipa 2 IPA is a Japanese quasi-government 3 organization established in accor- 4 dance with The Law for Information 5 Processing Technolog

1 $ cat aboutipa 2 IPA is a Japanese quasi-government 3 organization established in accor- 4 dance with The Law for Information 5 Processing Technolog 1 $ cat aboutipa 2 IPA is a Japanese quasi-government 3 organization established in accor- 4 dance with The Law for Information 5 Processing Technology Promotion, 6 (Law No.90, May 22, 1979). 7 $./upper

More information

memo

memo 数理情報工学演習第一 C ( 第 12 回 ) 2016/07/11 DEPARTMENT OF MATHEMATICAL INFORMATICS 1 今日の内容 : ファイルの入出力 コマンドライン引数 2 分探索 クイックソート ( ライブラリ ) 文字列検索 2 ファイル操作の手続き : ファイル操作 ファイルからのデータ読み込み ファイルへのデータ書き出し 基本的な手順 読みこむ / 書き出すファイルを開く

More information

Microsoft PowerPoint - kougi9.ppt

Microsoft PowerPoint - kougi9.ppt C プログラミング演習 第 9 回ポインタとリンクドリストデータ構造 1 今まで説明してきた変数 #include "stdafx.h" #include int _tmain(int argc, _TCHAR* argv[]) { double x; double y; char buf[256]; int i; double start_x; double step_x; FILE*

More information

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

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 C () 14 5 23 C () C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C 1.1 3 7 mandata mandata () name age income mandata () mandata1 1 #include struct mandata char name[51];

More information

数値計算

数値計算 プログラム作成から実行まで 数値計算 垣谷公徳 17 号館 3 階電子メール : kimi@ee.ous.ac.jp Source program hello.c printf("hello\n"); コンパイラ Library libc.a 0011_printf000101001 1101_getc00011100011 1011_scanf1110010100 コンパイル Object module

More information

I J

I J I 065763J 8 7 7 31 jikken/ +----- accumulation_demupa.c +----- accumulation_rain.c +----- frequency_demupa.c +----- frequency_rain.c +----- go.sh +----- graph_maker.sh +----- mesure-ryudai/ 2007/4/1 2007/6/30

More information

ポインタ変数

ポインタ変数 プログラミング及び実習 7 馬青 1 文字列処理 文字列 文字列は " ( ダブルクォーテーション ) で囲んで表現される 文字列というデータ型が存在しないので 文字列は文字の配列 あるいはポインタ変数として扱われる また 文字の配列あるいはポインタ変数を宣言するときのデータ型は char を用いる 従って char s[]="ryukoku Uni."; あるいは char *s="ryukoku

More information

ex01.dvi

ex01.dvi ,. 0. 0.0. C () /******************************* * $Id: ex_0_0.c,v.2 2006-04-0 3:37:00+09 naito Exp $ * * 0. 0.0 *******************************/ #include int main(int argc, char **argv) double

More information

untitled

untitled Q 8 1 8.1 (C++) C++ cin cout 5 C++ 16 6 p.63 8.3 #include 7 showbase noshowbase showpoint noshowpoint 8.3 uppercase 16 nouppercase 16 setfill(int) setprecision(int) setw(int) setbase(int) dec

More information

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

Microsoft PowerPoint - CproNt02.ppt [互換モード] 第 2 章 C プログラムの書き方 CPro:02-01 概要 C プログラムの構成要素は関数 ( プログラム = 関数の集まり ) 関数は, ヘッダと本体からなる 使用する関数は, プログラムの先頭 ( 厳密には, 使用場所より前 ) で型宣言 ( プロトタイプ宣言 ) する 関数は仮引数を用いることができる ( なくてもよい ) 関数には戻り値がある ( なくてもよい void 型 ) コメント

More information

Microsoft PowerPoint pptx

Microsoft PowerPoint pptx 情報処理 Ⅱ 第 12 13回 2011 年 1 月 31 17 日 ( 月 ) 本日学ぶこと ファイル入出力, 標準入力 標準出力 記憶域管理関数 (malloc など ) 問題 ファイルを入力にとり, 先頭に行番号をつけて出力できる? 行列の積を, ファイルを介して読み書き 計算できる? Wakayama University./line 1:Wakayama 2:University 3 2

More information

‚æ4›ñ

‚æ4›ñ ( ) ( ) ( ) A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 (OUS) 9 26 1 / 28 ( ) ( ) ( ) A B C D Z a b c d z 0 1 2 9 (OUS) 9

More information

C V C 6 1 6.1.............................. 1 6.......................... 3 6.3..................... 5 6.4 NULL............................. 8 6.5......................... 9 6.6..............................

More information

PowerPoint Presentation

PowerPoint Presentation ファイルの入出力 芝浦工業大学情報工学科 青木義満 今回の講義内容 ファイル入出力 ファイルからのデータ読込み ファイルと配列 2 1 ファイルへのデータ書き込み ( 復習 ) ソースファイル名 :fileio1.c データをファイルに書き込み #include int main(void) { ファイルポインタ宣言 int student_id = 100; char name[

More information

C B

C B C 095707B 2010 6 8 1 LEVE1 2 1.1 LEVEL 1.1................................................ 2 1.1.1 1................................................ 2 1.1.2 1.2..............................................

More information

BW BW

BW BW Induced Sorting BW 11T2042B 2015 3 23 1 1 1.1................................ 1 1.2................................... 1 2 BW 1 2.1..................................... 2 2.2 BW.................................

More information

ARM gcc Kunihiko IMAI 2009 1 11 ARM gcc 1 2 2 2 3 3 4 3 4.1................................. 3 4.2............................................ 4 4.3........................................

More information

2004 2005 2 2 1G01P038-0 1 2 1.1.............................. 2 1.2......................... 2 1.3......................... 3 2 4 2.1............................ 4 2.2....................... 4 2.3.......................

More information

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

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 >> 1 C++ 1.1 C C++ C++ C C C++ 1.1.1 C printf() scanf() C++ C hello world printf() 1-1 #include printf( "hello world\n" ); C++ 1-2 std::cout

More information

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

C言語によるアルゴリズムとデータ構造 Algorithms and Data Structures in C 4 algorithm List - /* */ #include List - int main(void) { int a, b, c; int max; /* */ Ÿ 3Ÿ 2Ÿ 3 printf(""); printf(""); printf(""); scanf("%d", &a); scanf("%d",

More information

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション プログラミング応用 第 15 回 知的情報システム学科張 暁華 プログラミング応用 1 授業のマナー ------ 人の話を聞くときの社会常識 1. 欠席者のかわりに登録を行わない 倫理に反することをやらない あなたの信を問われている蟻の穴から堤防が決壊 2. 私語しないこと : 質問 意見は手を挙げて大きな声ではっきりと意思表示 3. 授業以外のことをしない : 携帯をカバンにいれ イヤホンを使って音楽等を聞かない授業中ゲームを遊ばない

More information

Microsoft Word - no15.docx

Microsoft Word - no15.docx 7. ファイルいままでは プログラムを実行したとき その結果を画面で確認していました 簡単なものならそれでもいいのですか 複雑な結果は画面で見るだけでなく ファイルに保存できればよいでしょう ここでは このファイルについて説明します 使う関数のプロトタイプは次のとおりです FILE *fopen(const char *filename, const char *mode); ファイルを読み書きできるようにする

More information

第1回 プログラミング演習3 センサーアプリケーション

第1回 プログラミング演習3 センサーアプリケーション C プログラミング - ポインタなんて恐くない! - 藤田悟 fujita_s@hosei.ac.jp 目標 C 言語プログラムとメモリ ポインタの関係を深く理解する C 言語プログラムは メモリを素のまま利用できます これが原因のエラーが多く発生します メモリマップをよく頭にいれて ポインタの動きを理解できれば C 言語もこわくありません 1. ポインタ入門編 ディレクトリの作成と移動 mkdir

More information