|
|
- せいごろう やすこ
- 7 years ago
- Views:
Transcription
1 C Nishio, Quick guiprog/
2
3 C 1972 AT&T Dennis M. Ritchie Brian Wilson Kernighan 1, C 90 Java Visual Basic Java GUI C C C JAVA C++ C# C C C
4
5 5 1 C Visual C Express Edition Hello World printf n const
6 scanf scanf scanf if else if else switch break switch do while for do while while for break continue
7 main strcpy strlen strcat static #define #undef #include
8 NULL sizeof strlen strcat typedef
9
10 1 1 C 1.1 C 1 0 ON OFF 1.1:
11 1.2 C Visual C Express Edition C Visual C Express Edition Windows Linux OS gcc VC google Visual C Express Edition 1.2) 1.2: Visual C Express Edition Visual C Express Edition Web 1.3 2
12 1 C 1.3: Visual C Express Edition VC++ Visual C ) 1.4: Visual C Express Edition testproject 1.7 3
13 : 1.6: 4
14 1 C 1.7: cpp C test test.cpp
15 : cpp 1.9: 6
16 1 C 1.10: 1.11: 7
17 : C 2 int main(void) 3 { 4 /* */ 5 return 0; 6 } C C C main main C main 8
18 1 C main /* */ #include <stdio.h> stdio.h stdio (studio) stdio STanDard Input Output Hello World printf("hello World!"); /* */ 2 int main(void) 3 { 4 printf("hello World!"); 5 return 0; 6 } Hello World! printf printf printf printf() ( 9
19 1.3 printf(" "); printf C printf C printf("hello World"); \n \ n 2 2 printf("hello\nworld!\n"); : \n \a BEEP \0 NULL \t \b \? \ \" \\,
20 1 C 1.1 (\a) 3 (\t) NULL 4 printf("hello world!"); printf("hello world!\0"); NULL C NULL 1.1 \n \b \n \a \t \b New line( Alert( Tab( Back Space( 1.4 C 2 int main(void) 3 { 4 printf("hello world!"); /* Hello World! */ 5 return 0; 6 }
21 1.5 /* Hello World! */ /* */ ANSI C C /* */ // C99 C ANSI C C99 ANSI C int main(void) 4 { 5 /* */ 6 printf("this is a test program "); 7 printf("without indented. "); 8 /* 9 10 print("this line is not displayed. "); 12
22 1 C 11 */ 12 return 0; 13 } This line is not displayed... This is a test program without indented printf 1 printf, There are 10 types of people in this world. Those who understand binary and those who don t. Which one are you? 2 3 int main(void) 4 { 5 /* */ 6 printf("there are 10 types of people in this world." 7 "Those who understand binary and those who don t." 8 "Which one are you?\n" ); 9 return 0; 10 } There are 10 types of people in this world.those who understand binary and those who don t.which one are you?
23 1.6 He said, How dare you do to me like that! printf("he said, "How dare you do to me like that!""); /* error */ 2 3 int main(void) 4 { 5 printf("he said \"How dare you do to me like that!\""); 6 return 0; 7 } He said, How dare you do to me like that! int main(void) 4 { 5 printf("hello \0 world"); 6 return 0; 7 } 14
24 1 C 4 printf(). The ICMP source quench message is the TCP/IP equivalent of telling another computer: I can t keep up with all the traffic you re sending me - slow down, please. 5 5 Firewalls FOR DUMMIES by Brain Komar, Ronald Beekelaar, and Joern Wettern, PhD 15
25
26 17 2 C 2.1 C 2.1 short int long int int long int unsigned unsigned int -1 char
27 2.2 float,double double float int double char 2.1: short int long unsigned short unsigned int unsigned long char unsigned char float double * 10^ * 10^ * 10^ * 10^+308 C 2.1 char int OS 2.2 int 18
28 2 int hoge; hoge int double piyo double piyo; double foo, bar; double foo; double bar; { } 2 3 int main(void) 4 { 5 int hoge; 6 printf("hello"); 7 printf("world"); 8 9 return 0; 10 } ANSI C 2 3 int main(void) 4 { 5 /* */ 19
29 2.3 6 printf("hello"); 7 int hoge; 8 printf("world"); 9 10 return 0; 11 } { ( ) _( ( 2.2 int double 2.2: ( auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void defalut goto sizeof volatile do if static while 1 C C99 20
30 hoge int hoge; hoge = 10; = 2.1: int hoge = 10; x=10 x 10 if == 2.5 int hoge 10 int hoge; hoge = 10; printf("%d",hoge); 21
31 : %d 10, double float %f % 2.3: %d 10 %u 10 %o 8 %x 16 %f double float %c %s %p %% 22
32 2 2 int main(void) 3 { 4 int hoge = 10; 5 int piyo = 20; 6 double foo = ; 7 8 printf("hoge %d \n",hoge); 9 printf("piyo %d \n",piyo); 10 printf(" %d \n", 50); 11 printf("hoge %d piyo %d \n",hoge,piyo); 12 printf("foo %f \n",foo); 13 printf("hoge %f \n",hoge); 14 printf("foo %d \n",foo); 15 return 0; 16 } hoge 10 piyo hoge 10 piyo 20 foo hoge foo , int. 14 double.,. 23
33 2.6 n 2.3 %d %p ( %d %o %x %f %c %s %p Decimal Number( 10 Octal Number( 8 hexadecimal Number( 16 Floating Point Number( Character( String( Pointer( 2.6 n ,1 2? A F
34 A B C D E F : 2,10,16 25
35 int hoge; printf("hoge %d ",hoge); 0 Visual C Express Edition. 2.8 const const 2 const 2 int main(void) 3 { 4 const int i = 5; 5 printf("%d", i); 6 return 0; 7 } const 2 int main(void) 3 { 4 const int i = 5; 5 i = 10; /* */ 6 return 0; 7 } 2 const CONSTant( 26
36 2.9 2 C ( : + / 2 int main(void) 3 { 4 int x, y; 5 6 x = 10; 7 y = 20; 8 printf("x+y %d \n", x + y); 9 y = y - x; 10 printf("y %d \n", y); 11 return 0; 12 } x+y 30 y 10 27
37 int x = 7; int y = 3; printf("x/y %d ", x / y); 2 int double double x = 7; double y = 3; printf("x/y %f ", x / y); y int x = 10; printf(" %d \n", -x); int x = 10, y = 3; printf(" %d \n",x % y); 28
38 int x = 10; x += 10; x+= 10 x = x + 10 x -= 10; x /= 10; x 1 1 x++; 1 x--; C C++ C ++ C C B C D C# C# C++++, C x 2 x*x x^2 C 2 ^ xor 29
39 2.10 x*x x*x*x*x* pow pow pow( x, 4.0 ); x C double dx = 10.0, dz; int iy = 3; dz = dx / iy; int double iy double int double int double int double double dy = 10.0, dz; int iy = 3; dz = (int)dy / iy; dy int dy (int) double (double) 30
40 scanf scanf 2 3 int main(void) 4 { 5 int x; 6 7 printf(" :"); 8 scanf("%d", &x ); 9 printf(" %d \n", x); 10 return 0; 11 } scanf printf x & & scanf %d printf 10 x double %f %lf scanf scanf scanf scanf scanf C scanf gets sprintf 31
41 int hoge1; int hoge2; int hoge3; int hoge4; int hoge5; int hoge1; int hoge2; int hoge3; int hoge[5]; 3 [5] 100 int hoge[100]; [ ]; 3. hoge 32
42 int hoge[5]; : 10 hoge[0] = 10; ( : [0] 0 hoge[0] hoge[1] hoge[2] hoge[3] hoge[4] hoge[5] 33
43 int hoge[5] = { 1,2,3,4,5 }; 4 hoge[0] = 1; hoge[1] = 2; hoge[2] = 3; hoge[3] = 4; hoge[4] = 5; : int hoge[5] = {1,2}; 0 int hoge[5] = {1,2,0,0,0}; int hoge[] = {1,2,3,4,5}; [] [] int hoge[]; 0 int hoge[0]; 4 34
44 char char 1 char str; str = A ; 1 char str[6] = { H, E, L, L, O, \0 }; printf("%c%c%c%c%c%c",str[0],str[1],str[2],str[3],str[4],str[5]); str[5] NULL 5 printf 1 %c %s char str[6] = { H, E, L, L, O, \0 }; printf("%s",str); printf str [0] str &str[0] char str[6] = {"HELLO"}; char str[6] = "HELLO"; 5 35
45 2.12 \0 \0 char str[5] = "HELLO"; \ scanf 2 3 int main(void) 4 { 5 char str[6]; 6 7 printf(" "); 8 scanf("%s", str); 9 printf(" %s.\n", str ); 10 return 0; 11 } HELLO HELLO HELLO %s scanf str & scanf("%s", &str[0]);, 36
46 2 2.6: scanf scanf %s 2 3 int main(void) 4 { 5 char str[100]; 6 7 printf(" "); 8 scanf("%s", str); 9 printf(" :%s.\n", str ); 10 return 0; 11 } HELLO WORLD HELLO WORLD HELLO HELLO gets 37
47 C 1 char char char hoge; hoge = 97; hoge 97 char char hoge; hoge = a ; char ( 2.7) Windows SHIFT JIS a C 16 0x char hoge = 0x61; 38
48 2 2.7: JIS 39
49 char hoge = 1 ; char hoge = 1; 1 0x ( char
50 2 2 3 int main(void) 4 { 5 double meter; 6 double answer; 7 8 printf(" :"); 9 scanf("%lf",&meter); 10 answer = meter * 3.2; 11 printf("%f %f \n", meter, answer); 12 return 0; 13 } : scanf HELLO WORLD Enter HELLO gets() scanf(),. %[0-9] int main(void) 4 { 5 char str[80]; 6 7 printf("enter :"); 8 scanf("%[a-za-z ]",str); 9 printf("answer :%s\n",str); 10 return 0; 11 } 41
51 2.15 enter :HELLO WORLD answer :HELLO WORLD (C) (F) (C) (F) F = 9 5 C int main(void) 4 { 5 int i = 3, j = 5; 6 printf("%d", i / j); 7 return 0; 8 } int main(void) 42
52 2 4 { 5 char str[5] = "HELLO WORLD"; 6 printf("%s", str); 7 return 0; 8 }
53
54 if else if else if else : if else if else if else int hoge hoge 10 A B
55 3.1 if else 2 3 int main(void) 4 { 5 int hoge = 10; 6 7 if( hoge == 10 ) { 8 /* A */ 9 } else { 10 /* B */ 11 } 12 } if if( ). (true) A (false) B,hoge 10 A,hoge = 10,hoge == 10. =. (, ==., A if( hoge == 10 ) { /* hoge 10 */ },,. int hoge = 8; if( hoge == 10 ){ /* A */ }else if( hoge == 9) { /* B */ }else if( hoge == 8 ) { /* C */ }else{ /* D */ } 46
56 3 C. hoge 9 B,6 D int hoge = 1; if( hoge ){ /* */ },, hoge.., 0 0.,hoge 0 (true,0 false.,. if( hoge!= 0 ) { /* */ }!=. hoge 0.. if( 1 ) { /* A */ } else { /* B */ } A. 0 A. 0 B. 47
57 3.1 if else if( hoge = 3 ) { /* hoge 3 A */ } else { /* hoge 3 B */ } C hoge == 3 hoge = 3 A hoge 3 true if( 3 == hoge ) { /* hoge 3 A */ } else { /* hoge 3 B */ } 3 = hoge if hoge = 3 JAVA 3.1.3, i j i j 48
58 3 3.1: x < y x y, x > y x y, x <= y x y, x >= y x y, x == y x y, x!= y x y, 2 3 int main(void) 4 { 5 int i, j; 6 7 printf("i :"); 8 scanf("%d", &i); /* i */ 9 printf("j :"); 10 scanf("%d", &j); /* j */ if( i < j ) { 13 /* i j */ 14 printf("i j \n"); 15 } else { 16 printf("i j \n"); 17 } 18 } i 10 j 5 i : 10 j : 5 i j
59 3.1 if else int hoge = 10, piyo = 20; if( hoge == 10 ) { if( piyo == 20 ) { /* A */ } }, hoge 10, piyo 20, A. ( 3.2 if 3.2: x == 10 && y == 20 x == 10 y == 20!x x x 10 y 20 x 10 y 20. if( hoge == 10 && piyo == 20){ /* A */ } 3.2 x. int hoge = 10; if(!hoge ){ /* A */ }!hoge hoge A hoge 0 A 50
60 3 3.2 switch if, switch. switch,if 1 int hoge = 8; 2 3 if( hoge == 10 ){ 4 /* A */ 5 }else if( hoge == 9) { 6 /* B */ 7 }else if( hoge == 8 ) { 8 /* C */ 9 }else{ 10 /* D */ 11 } if : if else 51
61 3.2 switch, hoge 7,hoge 6,. 1 switch. switch. 2 3 int main(void) 4 { 5 int hoge = 8; 6 switch( hoge ) { 7 case 10: /* A */ 8 break; 9 case 9 : /* B */ 10 break; 11 case 8 : /* C */ 12 break; 13 default: /* D */ 14 break; 15 } 16 /* E */ 17 } 3.3: switch switch 3.3 if-else switch 1 52
62 3 switch. hoge,hoge. hoge 8,case 8:. break,break switch. case 8: C E default if else break switch switch break int main(void) 4 { 5 int hoge = 9; 6 switch( hoge ) { 7 case 10: printf("10\n"); case 9 : printf("9\n"); 11 case 8 : printf("8\n"); default: printf("7\n"); } 16 return 0; 17 } C case 9: case 8:. 53
63 3.3 do while for (fall through ) fall through break 3.3 do while for do while for do while Hello world 10 do while. 2 int main(void) 3 { 4 int hoge = 10; 5 6 do{ 7 printf("%d :Hello world\n", 11 - hoge); 8 hoge--; 9 }while( hoge > 0); return 0; 12 } 1 :Hello world 2 :Hello world 3 :Hello world 4 :Hello world 5 :Hello world 6 :Hello world 7 :Hello world 8 :Hello world 9 :Hello world 10 :Hello world 54
64 3 do while do { } while( ); do{ }. do{ : do while,while while do while while. do while while, ( 3.5. do while 1 while Hello world 10 while. 55
65 3.3 do while for 3.5: while 2 int main(void) 3 { 4 int hoge = 10; 5 while( hoge > 0 ) { 6 printf("%d :Hello world\n", 11 - hoge); 7 hoge--; 8 } 9 return 0; 10 } while. while( ) { } if while( 1 ) { printf("hello world\n"); } 56
66 3, for for while while for. 2 3 int main(void) 4 { 5 int hoge; 6 for( hoge = 10; hoge > 0 ; hoge--) { 7 printf("%d :Hello world\n",11-hoge); 8 } 9 return 0; 10 } for for( ; ; ) { } if Hello world hoge--,., int hoge = 10; for( ; hoge > 0 ; hoge--) { printf("%d :Hello world\n",11-hoge); }. for while. 57
67 while 3.3 do while for A; while( B ) { C; } for for for( A ; B ; C ) { } for while.. for(;;){ } break break 2 3 int main(void) 4 { 5 int i; 6 7 for( i = 0; i < 10; i++ ) { 8 printf("i :%d\n", i); 9 if( i == 5 ) { 10 break; 11 } 12 } 13 printf(" \n"); 14 return 0; 15 } 58
68 3 3.6: break 3.6 i :0 i :1 i :2 i :3 i :4 i :5 break continue continue 59
69 int main(void) 4 { 5 int i; 6 for( i = 0; i < 5; i++ ) { 7 printf("i :%d\n", i); 8 if( i <= 2 ) { 9 continue; 10 } 11 /* i <= 2 */ 12 printf("loop-----\n"); 13 } 14 return 0; 15 } i :0 i :1 i :2 i :3 LOOP i :4 LOOP continue break for do while
70 C, & AND( OR ^ XOR ~ NOT AND & 0 => 0 0 & 1 => 0 1 & 0 => 0 1 & 1 => AND OR => => => => 1 OR XOR( EOR) XOR ^ 0 => 0 0 ^ 1 => 1 1 ^ 0 => 1 1 ^ 1 => 0 61
71 3.4 NOT 1 ~0 => 1 ~1 => int main(void) 4 { 5 unsigned char and,or,xor,not; 6 unsigned char hoge,piyo; 7 8 hoge = 187; /* */ 9 piyo = 86; /* */ and = hoge & piyo; 12 or = hoge piyo; 13 xor = hoge ^ piyo; 14 not = ~piyo; printf("hoge AND piyo = %d\n",and); 17 printf("hoge OR piyo = %d\n",or); 18 printf("hoge XOR piyo = %d\n",xor); 19 printf(" NOT piyo = %d\n",not); return 0; 22 } hoge AND piyo = 18 hoge OR piyo = 255 hoge XOR piyo = 237 NOT piyo =
72 3 hoge (187) (187) AND piyo (86) OR (86) (18) (255) hoge (187) XOR piyo (86) NOT (86) (237) (169) C << >> 2. 2 int main(void) 3 { 4 unsigned char hoge = 4; 5 6 hoge = hoge << 3; 7 printf("hoge 3 :%d",hoge); 8 return 0; 9 } 2 63
73 3.5 hoge 3 :32 hoge 8 hoge (4) hoge << (32) , 1 /* 1 */ 2 #include <stdio.h> 3 4 int main(void) 5 { 6 char source[100], str[100]; 7 int i; 8 9 printf(" :"); 10 scanf("%s", source ); for( i = 0; source[i]!= \0 ; i++ ){ 13 str[i] = source[i]; 14 } 15 str[i] = \0 ; printf(" %s ",str); 18 return 0; 19 } 64
74 3 NULL for source 0 str source[i] NULL. 1 /* 2 */ 2 #include <stdio.h> 3 4 int main(void) 5 { 6 char source[100], str[100]; 7 int i; 8 9 printf(" :"); 10 scanf("%s", source ); i = 0; 13 while( source[i]!= \0 ) { 14 str[i] = source[i]; 15 i++; 16 } 17 str[i] = \0 ; printf(" %s ",str); 20 return 0; 21 } :HELLOWORLD HELLOWORLD ,. 65
75 3.5 1 /* */ 2 #include <stdio.h> 3 4 int main(void) 5 { 6 int array[10]; 7 int i,j,max; 8 9 printf("10 \n"); for( i = 0 ; i < 10 ; i++ ) { 12 printf("%d :",i+1); 13 scanf("%d", array ); 14 } for( j = 1, max = array[0] ; j < 10; j++) { 17 if( max < array[j] ) { 18 max = array[j]; 19 } 20 } printf(" %d ",max); 23 return 0; 24 } 1 :5 2 :8 3 :13 4 :4 5 :90 6 :54 7 :30 8 :52 9 :70 10 :
76 int main(void) 4 { 5 int i,j; 6 7 for( i = 1 ; i < 10 ; i++ ) { 8 for(j = 1 ; j!= 10 ; j++ ) { 9 printf("%3d ",i * j); 10 } 11 printf("\n"); 12 } 13 return 0; 14 } printf %3d 3.. 5,%5d. 67
77 ) A B 2 3 int main(void) 4 { 5 int hoge; 6 7 for( hoge = 0; hoge < 256 ; hoge++ ) { 8 printf("%3d %3x %c\n",hoge,hoge,hoge); 9 } 10 return 0; 11 } 3.5.5, 2 3 int main(void) 68
78 3 4 { 5 int hoge, piyo; 6 int select; 7 8 printf("1 : \n" 9 "2 : \n"); 10 printf(" :"); scanf("%d",&select); 13 printf("hoge :"); scanf("%d",&hoge); 14 printf("piyo :"); scanf("%d",&piyo); switch(select) { 17 case 1: printf("%d + %d = %d\n",hoge,piyo, hoge + piyo); 18 break; 19 case 2: printf("%d - %d = %d\n",hoge,piyo, hoge - piyo); 20 break; 21 } 22 return 0; 23 } 1 : 2 : :1 hoge :15 piyo : = ,60 69
79 int main(void) 4 { 5 6 int student[5]; 7 int i; 8 9 for(i = 0; i < 5; i++){ 10 printf(" %d :",i + 1); 11 scanf("%d",&student[i]); 12 } 13 for(i = 0; i < 5; i++){ 14 if(student[i] > 60) { 15 printf(" %d %d \n",i+1, student[i]); 16 } 17 } 18 return 0; 19 } 1 :68 2 :57 3 :30 4 :90 5 :
80 IP IP AND IP int main(void) 3 { 4 unsigned char ip_address[4] = {192,168,12,9}; 5 unsigned char subnetmask[4] = {255,255,255,0}; 6 unsigned char net_add[4] = {0}; 7 int i; 8 9 for(int i = 0; i < 4; i++){ 10 net_add[i] = ip_address[i] & subnetmask[i]; 11 } 12 printf("network_address is %d.%d.%d.%d\n", 13 net_add[0],net_add[1],net_add[2],net_add[3]); 14 return 0; 15 } network address is ,
81 , 3 4, NULL \0). 5 ***** *** * * *** ***** Fizz Buzz 1 3 Fizz 5 Buzz Fizz Buzz [wikipedia ] 72
82 3 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz Buzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, Fizz Buzz, 31, 32, Fizz, 34, Buzz, Fizz, Fizz 5 Buzz 3 5 FizzBuzz modulo % 8 Fizz Buzz hoge, piyo, foo, bar. 2 3 int main(void) 4 { 5 int hoge = 0, piyo = 0; 6 int foo = 0, bar = 0; 7 8 do{ 9 printf("hoge\n"); 10 }while( hoge++ < 3); while( piyo++ < 3){ 13 printf("piyo\n"); 14 } 15 73
83 do{ 17 printf("foo\n"); 18 } while(++foo < 3); while(++bar < 3){ 21 printf("bar\n"); 22 } 23 return 0; 24 } 2 IPAddress , Subnetmask WWW. ISP /29. IP. 3 2 int main() 3 { 4 unsigned char ip_address[4] = {210,175,166,160}; 5 unsigned char subnetmask[4] = {255,255,255,248}; 6 unsigned char net_add[4] = {0}; 7 unsigned char bro_add[4] = {0}; 8 int host_num = 0; 74
84 int i; 11 for(int i = 0; i < 4; i++){ 12 net_add[i] = ip_address[i] & subnetmask[i]; 13 } /* */ 16 for(int i = 0; i < 4; i++){ 17 if(subnetmask[i]!= 255){ 18 bro_add[i] = net_add[i] + ~subnetmask[i]; 19 }else{ 20 bro_add[i] = ip_address[i]; 21 } 22 } printf("network_address is %d.%d.%d.%d\n", 25 net_add[0],net_add[1],net_add[2],net_add[3]); 26 printf("broadcast_address is %d.%d.%d.%d\n", 27 bro_add[0],bro_add[1],bro_add[2],bro_add[3]); for(int i = 0; i < 4; i++){ 30 host_num += (bro_add[i] - net_add[i]) << 24-8 * i; 31 } /* */ 34 host_num = host_num - 1; 35 printf(" %d \n",host_num); return 0; 38 } 75
85
86 C printf scanf int Plus(int x, int y) 4 { 5 int result; 6 result = x + y; 7 return result; 8 } 9 10 int main(void) 11 { 12 int hoge,piyo; 13 int n; printf("2 \n"); 16 printf("1 :"); scanf("%d",&hoge); 17 printf("2 :"); scanf("%d",&piyo); n = Plus(hoge,piyo); 20 printf(" %d \n",n); 21
87 return 0; 23 } :5 2 :10 15 ( ) { } main Plus 4.1: printf Plus main n = Plus( hoge, piyo); Plus n n n int 78
88 4 Plus( hoge, piyo ); ( ) : 4.2 void Test(int x) { x = 10; } int main(void) { int hoge; Test( hoge ) } return 0; x hoge x hoge Test 79
89 4.3 void void void Test2(void) { printf("test FUNCTION\n"); } int main(void) { Test2(); return 0; } return Plus result 4.3 C 2 3 int main(void) 4 { 5 Test2(); 6 return 0; 7 } 8 9 void Test2(void) 10 { 11 printf("test FUNCTION\n"); 12 } main Test2 Test2 80
90 4 2 3 void Test2(void); /* */ 4 5 int main(void) 6 { 7 Test2(); 8 return 0; 9 } void Test2(void) 12 { 13 printf("test FUNCTION\n"); 14 } main Test2 Test2() ( ; ) 4.4 ( 2 3 void show(int array[5], int n) 4 { 5 int i; 6 for( i = 0; i < n ; i++ ) { 7 printf("%d\n", array[i]); 8 } 9 } int main() 12 { 13 int array[] = {1, 2, 3, 4, 5}; 81
91 show( array, 5 ); 15 return 0; 16 } array show array show void show(int array[], int n) { int i; for( i = 0; i < n ; i++ ) { printf("%d\n", array[i]); } } array show void show(int *array, int n) { int i; for( i = 0; i < n ; i++ ) { printf("%d\n", array[i]); } } 82
92 4 4.5 main main main main int BP_SYM( ) { result = main(argc,argv, environ); } exit(result); main exit exit 0 0 main int main(void) { return 1; } main void main(void) { /* */ } void main(void) 83
93 C printf scanf printf stdio.h #include <stdio.h> printf string.h #include <string.h> strcpy char *strcpy(char* str1, const char* str2); strcpy const 2 #include <string.h> 3 4 int main(void) 5 { 6 char source[20] = "hello"; 7 char dest[20]; 8 9 strcpy( dest, source ); 10 printf(" %s \n", dest); 11 return 0; 12 } 84
94 4 4.3: strcpy hello strncpy char *strncpy(char* str1, const char* str2, size_t n); n str2 n n, NULL str2 n,str1 NULL NULL strcpy strncpy NULL 2 #include <string.h> 3 4 int main(void) 5 { 6 char source[20] = "helloworld"; 7 char dest[20]; 8 9 strncpy( dest, source, 5); 10 dest[5] = \0 ; /* */ 11 printf(" %s \n", dest); 12 return 0; 85
95 } hello strlen size_t strlen(const char* str); strlen str NULL 1 size t unsigned int 2 #include <string.h> 3 4 int main(void) 5 { 6 char source[20] = "hello"; 7 printf(" %d \n", strlen(source) ); 8 return 0; 9 } 5 strcat char* strcat(char* str1, const char* str2); strcat str1 str2 2 #include <string.h> 3 1 unsigned int. 86
96 4 4 int main(void) 5 { 6 char source[80] = "world"; 7 char dest[80] = "hello"; 8 9 strcat(dest, source); 10 printf(" %s\n", dest ); 11 return 0; 12 } helloworld strncat char* strncat(char* str1, const char* str2, size_t n); strncat str1 str2 n 2 #include <string.h> 3 4 int main(void) 5 { 6 char dest[20] = "ABC"; 7 char source[20] = "DEFGH"; 8 9 strncat(dest, source, 3); 10 printf(" %s\n", dest); 11 return 0; 12 } ABCDEF 87
97 4.6 strcmp int strcmp(const char* str1, const char* str2); strcmp str1 str2 0 str1 str2 str1 str #include <string.h> 3 4 int main(void) 5 { 6 char source[80] = "hello"; 7 char dest[80] = "hello"; 8 9 if( strcmp(source, dest) == 0 ) { 10 printf(" \n"); 11 } else { 12 printf(" \n"); 13 } 14 return 0; 15 }
98 4 putchar int putchar(int c); c 1 stdio.h 2 3 int main(void) 4 { 5 putchar( a ); 6 } a puts int puts (const char *str); str printf %d \n stdio.h 2 3 int main(void) 4 { 5 puts("hello world"); 6 } hello world 89
99 4.6 getchar int getchar(void); stdio.h 2 3 int main() 4 { 5 char ch; 6 7 printf(" "); 8 ch = getchar(); 9 10 printf(" :%c\n", ch); 11 return 0; 12 } a a a gets char *gets (char *str); scanf stdio.h 2 3 int main() 90
100 4 4 { 5 char str[80]; 6 7 printf(" "); 8 gets( str ); 9 printf(" :%s\n", str); 10 return 0; 11 } hello world hello world hello world fgets char *fgets( char *string, int n, FILE *stream ); stream n - 1 string stream stream stdin stdio.h 2 3 int main() 4 { 5 char str[80]; 6 7 printf(" "); 8 fgets(str, 6, stdin); 9 printf(" :%s\n", str); 10 return 0; 11 } 91
101 4.6 helloworld helloworld hello math.h sin double sin( double arg ); sin arg sin 2 #include <math.h> 3 4 int main(void) 5 { 6 double value = -1.0; 7 printf("%f sin %f \n",value,sin(value)); 8 9 return 0; 10 } sin
102 4 cos double cos( double arg ); cos arg cos 2 #include <math.h> 3 4 int main(void) 5 { 6 double value = -1.0; 7 printf("%f cos %f \n",value,cos(value)); 8 9 return 0; 10 } cos pow double pow(double x, double y); pow x y 2 #include <math.h> 3 4 int main(void) 5 { 6 double x = 2.0, y = 5.0; 93
103 4.6 7 printf("%f %f %f ", x, y, pow(x, y) ); 8 9 return 0; 10 } atoi int atoi( const char *string ); string int stdlib.h 2 #include <stdlib.h> 3 4 int main(void) 5 { 6 char str[]="150"; 7 8 printf(" %s %d \n", str, atoi(str) ); 9 return 0; 10 }
104 4 toupper int toupper( int c ); c stdlib.h 2 #include <stdlib.h> 3 4 int main(void) 5 { 6 char ch = a ; 7 printf("%c %c \n", ch, toupper(ch) ); 8 9 return 0; 10 } a A tolower int tolower( int c ); c stdlib.h 2 #include <stdlib.h> 3 4 int main(void) 95
105 4.7 5 { 6 char ch = A ; 7 printf("%c %c \n", ch, tolower(ch) ); 8 9 return 0; 10 } A a strcpy strcpy my strcpy 2 3 void my_strcpy(char dest[], char source[]) 4 { 5 int i; 6 7 for( i = 0; source[i]!= \0 ; i++ ) { 8 dest[i] = source[i]; 9 } 10 dest[i] = \0 ; 11 } int main() 14 { 15 char source[100] = "hello"; 16 char dest[100]; my_strcpy(dest, source); 19 printf(" %s \n", dest); 96
106 4 20 return 0; 21 } strcpy hello strlen strlen my strlen 2 3 int my_strlen(char str[]) 4 { 5 int i = 0; 6 7 for( i = 0; str[i]!= \0 ; i++ ) 8 ; 9 return i; 10 } int main() 13 { 14 char buf[100] = "hello"; printf("%s %d \n", buf, my_strlen(buf) ); 17 return 0; 18 } hello 5 97
107 strcat strcat my strcat 2 #include <string.h> 3 4 void my_strcat(char dest[], char source[]) 5 { 6 int i; 7 int len = strlen( dest ); 8 9 for( i = 0; source[i]!= \0 ; i++ ) { 10 dest[ i + len ] = source[i]; 11 } 12 dest[i + len] = \0 ; 13 } int main(void) 16 { 17 char source[100] = "world"; 18 char dest[100] = "hello"; my_strcat( dest, source ); 21 printf(" %s\n", dest ); 22 return 0; 23 } helloworld 98
108 Power( 2, 5 ) 2 3 int Power(int x, int y); /* */ 4 5 int main(void) 6 { 7 int xi,yi; 8 9 printf(" :"); 10 scanf("%d",&xi); 11 printf(" :"); 12 scanf("%d",&yi); printf("%d %d %d \n",xi,yi,power(xi,yi)); 15 return 0; 16 } int Power(int x, int y) 19 { 20 int i,result; for( i=1, result = 1; i <= y; i++) { 23 result *= x; 24 } 25 return result; 26 }
109 strncpy 2 strncat 3 reverse 4 source ch 5 palindrome radar madamimadam( = Madam, I m Adam ) 100
110 void func(void); 3 4 int main(void) 5 { 6 int hoge; 7 ) 8 return 0; 9 } void func(void) 12 { 13 int hoge; 14 } int hoge hoge main hoge main main hoge func hoge func 2 void func(void) 3 4 int main(void)
111 5.1 5 { 6 int hoge; 7 ( ) 8 return 0; 9 } 10 void func(void) 11 { 12 hoge = 10; 13 } hoge main main 2 3 int hoge; /* */ 4 5 void func(void); 6 7 int main(void) 8 { 9 int hoge; /* */ 10 hoge = 20; 11 ( ) 12 return 0; 13 } 14 void func(void) 15 { 16 int x; 17 int hoge = 10; /* */ for(x=0; x < 10 ; x++ ) { 20 int hoge; /* */ 21 hoge = x; 22 } 23 } 1 hoge 1 hoge main 102
112 5 hoge hoge 1 hoge 2 hoge main main hoge 3 hoge func 4 hoge for int main(void) { int hoge; int hoge; } return 0; static 2 3 int main(void) 4 { 5 static int x = 10; 6 ( ) 7 return 0; 8 } static static static 2 3 void func(void); 4 5 int main(void) 103
113 5.2 6 { 7 func(); 8 func(); 9 func(); 10 return 0; 11 } void func(void) 14 { 15 static int hoge = 10; 16 hoge++; 17 printf("hoge = %d\n",hoge); 18 } hoge = 11 hoge = 12 hoge = 13 func 10 static #define #define #define A B #define A B 2 #define NUMBER int main(void) 104
114 5 5 { 6 printf("%d",number); 7 return 0; 8 } NUMBER 10 NUMBER #define #define #undef #undef #undef A #undef NUMBER #define NUMBER 11 #undef NUMBER define 2 3 #define SUM( x, y ) ( (x) + (y) ) 4 5 int main(void) 6 { 7 int sum; 8 105
115 5.2 9 sum = SUM(3,5); 10 printf("%d",sum); return 0; 13 } SUM(3,5) ((3) + (5)) #define SQR(x) x*x int x = SQR( a + b ); int y = SQR( a ) / SQR( b ); a b int x = a+b * a+b; int y = a*a / b*b; a 3 b 4 x * y #define SQR(x) ((x)*(x)) #include #include printf printf printf stdio.h stdio.h printf scanf 106
116 5 #include < > #include " " #include 2 < > int num = 10; 4 5 void func(int number) 6 { 7 printf("num = %d\n", num); 8 number = 20; 9 } int main(void) 12 { 13 int num = 3; printf("num = %d\n", num); 16 func( num ); 17 printf("num = %d\n", num); 18 return 0; 19 } 107
117 #define TIMES( x, y ) ( x * y ) 4 5 int main(void) 6 { 7 int num; 8 9 num = TIMES( 3 + 5, ); 10 printf("%d\n",num); return 0; 13 } 108
118 109 6 C hoge C int hoge int hoge; hoge int hoge hoge 6.1 hoge hoge 100 p_piyo p_piyo hoge
119 : 6.2: hoge p piyo 110
120 6 int int double double double int int p piyo int* p_piyo; int *p_piyo; int *p_hoge,*p_piyo p hoge p piyo int* p_hoge, p_piyo p hoge p piyo int 6.2 int hoge; int int hoge 100 int* p_piyo 6.3 p piyo 111
121 : int hoge; int* p_piyo; hoge = 10; p_piyo = &hoge; int hoge int( hoge hoge = 10; hoge 10 p_piyo p_piyo = hoge; 6.4 p_piyo int* int* (int ( 6.4: p_piyo hoge & p_piyo = &hoge
122 6 6.5: & &hoge hoge int main(void) 4 { 5 int hoge; 6 int* p_piyo; 7 8 hoge = 10; 9 p_piyo = &hoge; printf("hoge address :%p\n", &hoge); 12 printf("hoge :%d\n", hoge); 13 printf("p_piyo :%p\n", p_piyo); 14 printf("*p_piyo:%d\n", *p_piyo); 15 printf("p_piyo address :%p\n", &p_piyo); 16 } printf %p
123 : printf("hoge address :%p\n",&hoge); & hoge address : printf("hoge :%d\n",hoge); hoge printf("p_piyo :%p\n",p_piyo); p_piyo printf("*p_piyo:%d\n",*p_piyo); *p_piyo *p_piyo : 10 hoge *p_piyo p_piyo p_piyo hoge *p_piyo * * int* p_hoge; /* * */ OS hoge address :0012F
124 6 int piyo = 10; p_hoge = &piyo; /* p_hoge piyo * */ printf("%d", *p_hoge); * * printf("p_piyo address :%p\n", &p_piyo); hoge address : 100 hoge : 10 p_piyo : 100 *p_piyo : 10 p_piyo address : 150 C void* 1 int main(void) 2 { 3 int hoge = 10; 4 void* p_piyo = &hoge; 5 6 /* bar = *p_piyo */ 7 int bar = *( (int*)p_piyo ); 8 9 return 0; 10 } int bar = *p_piyo; 115
125 6.4 NULL p piyo ( hoge) int* p_piyo hoge *p_piyo 6.7: 6.4 NULL int hoge; printf("%d",hoge); hoge int* p p p 116
126 6 p = NULL; p NULL p NULL 2 NULL #define NULL 0 p = NULL p = 0 p = 0 #define NULL ( (void*)0 ) NULL int* p = NULL printf("%d",*p); p 3 int* int* p_piyo = 10; NULL 0 int* p_piyo = 0; C 0 0 NULL swap 1 void swap( int x, int y ) 2 { 3 int tmp = x; 2 NULL 3 Java NullPointerException 4 0 NULL JAVA null 117
127 6.5 4 x = y; 5 y = tmp; 6 } 2 3 void swap( int x, int y ) 4 { 5 int tmp = x; 6 x = y; 7 y = tmp; 8 } 9 10 int main(void) 11 { 12 int hoge = 10, piyo = 5; swap( hoge, piyo ); 15 printf("hoge : %d, piyo : %d\n",hoge, piyo); 16 return 0; 17 } hoge : 10, piyo : 5 swap x y hoge piyo 2 118
128 6 6.8: 3 void swap(int* x, int* y); /* */ 4 5 int main(void) 6 { 7 int hoge = 10, piyo = 5; 8 9 swap( &hoge, &piyo ); 10 printf("hoge : %d, piyo : %d\n",hoge,piyo); 11 return 0; 12 } void swap(int* x, int* y) 15 { 16 int tmp = *x; 17 *x = *y; 18 *y = tmp; 19 } 6.9 *x hoge *y piyo hoge : 5, piyo : 10 hoge piyo &hoge scanf 119
129 : & 6.6 int char double : short int long unsigned short unsigned int unsigned long char unsigned char float 3.4 * 10^ * 10^+38 double 1.7 * 10^ * 10^
130 6 int char char 1 int char char sizeof sizeof sizeof int return 2 int main(void) 3 { 4 char hoge; 5 int piyo; 6 7 printf("char %d ", sizeof(hoge) ); 8 printf("int %d ", sizeof(piyo) ); 9 return 0; 10 }
131 6.6 char 1 int int main(void) 3 { 4 char* p_hoge; 5 int* p_piyo; 6 7 printf("char* %d \n", sizeof(p_hoge) ); 8 printf("int* %d \n", sizeof(p_piyo) ); 9 return 0; 10 } char* 4 int* int main(void) 3 { 4 int array[5] = {5,10,15,20,25}; 5 int* p; 8 int* char* 122
132 6 6 p = &array[0]; 7 8 printf("p[0] = %d\n",*p); 9 p++; 10 printf("p[1] = %d\n",*p); 11 } main : 6.11: 123
133 6.6 Array[0] 100 int 4 Array[1] 104 p++; p int p++; : 4 int* char* =101 p[0] = 5 p[1] =
134 int main(void) 4 { 5 int array[5] = { 1, 2, 3, 4, 5 }; 6 int* p; 7 8 p = &array[0]; 9 10 printf("*(p+0) : %d\n", *(p + 0) ); 11 printf("*(p+1) : %d\n", *(p + 1) ); 12 printf("*(p+3) : %d\n", *(p + 3) ); 13 return 0; 14 } int array[5] = { 1, 2, 3, 4, 5 }; int* p; p = &array[0]; 6.13 array[0] 100 int 4 array[1] 104 array array[0] array[4] 5 array array[4] 116 int* p p = array[0]; 125
135 : array[0] int p int* (int) int* array[0] p = &array[0]; & array[1] p p = &array[1]; printf("*(p+0) : %d\n", *(p+0) ); printf("*(p+1) : %d\n", *(p+1) ); printf("*(p+3) : %d\n", *(p+3) ); *p p 100 *p 100 array[0] *(p + 0) *(p) *p p
136 6 6.14: printf("*(p+0) : %d\n", *(p+0) ); array[0] 1 printf("*(p+0) : %d\n", *(p+1) ); p int size 4 p+1 int 4 p p+1 p 100 int *(p+0) *(100 ) *(p+1) *( ) *(104 ) 2 array[1] printf("*(p+0) : %d\n", *(p+3) ); *(p+0) : 1 *(p+1) : 2 *(p+3) : 4 127
137 6.7 *( p + 1 ); p int main(void) 4 { 5 int array[5] = { 1, 5, 10, 15, 20 }; 6 int* p; 7 8 p = &array[0]; 9 printf("array[0] : %d\n", *(p + 0) ); 10 printf("array[1] : %d\n", *(p + 1) ); printf("*p+1 : %d\n", *p + 1 ); return 0; 15 } array[0] : 1 array[1] : 5 *p+1 : 2 *(p + 1) *p * (3 + 5) 9 C *p + 1 * + * *p *p printf("*p+1 : %d\n", *p + 1 ); 2 p 1 128
138 6 printf("*p+1 : %d\n", *(p + 1) ); 2 3 int main(void) 4 { 5 int array[5] = { 1, 2, 3, 4, 5 }; 6 int* p; 7 8 p = &array[0]; 9 10 printf("*(p+0) : %d\n", *(p+0) ); 11 printf("*(p+1) : %d\n", *(p+1) ); 12 printf("*(p+3) : %d\n", *(p+3) ); 13 return 0; 14 } p = &array[0]; p = array; 2 3 int main(void) 4 { 5 int array[5] = { 1, 2, 3, 4, 5 }; 6 int* p; 7 8 p = array; /* p array */ 9 10 printf("*(p+0) : %d\n", *(p+0) ); 11 printf("*(p+1) : %d\n", *(p+1) ); 129
139 printf("*(p+3) : %d\n", *(p+3) ); 13 return 0; 14 } array p int main(void) 4 { 5 int array[5] = { 1, 2, 3, 4, 5 }; 6 int* p; 7 8 p = array; /* p array */ 9 10 printf("p[0] : %d\n", p[0] ); 11 printf("p[1] : %d\n", p[1] ); 12 printf("*(p+1) : %d\n", *(p + 1) ); 13 return 0; 14 } p[0] : 1 p[1] : 2 *(p+1) : 2 p[0] p array p[0] *(p + 0) p[1] *(p + 1) *(p + 1) p[1] 130
140 6 2 3 int main(void) 4 { 5 int array[5] = { 1, 2, 3, 4, 5 }; 6 int* p; 7 8 p = &array[1]; /* array[1] */ 9 10 printf("p[0] : %d\n", p[0] ); 11 printf("p[1] : %d\n", p[1] ); 12 printf("p[-1]: %d\n", p[-1] ); 13 return 0; 14 } p[0] : 2 p[1] : 3 p[-1]: 1 p[-1] array[-1] p[-1] *(p - 1) *(p + 1) *(1 + p) (3 + 5) (5 + 3) *(1 + p) 1[p] int i; 2 3 void myputs(char str[20]) 131
141 6.7 4 { 5 int i; 6 for( i = 0; str[i]!= \0 ; i++ ) { 7 putchar( str[i] ); 8 } 9 printf("\n"); 10 } int main(void) 13 { 14 char str[20] = "Hello world"; 15 myputs( str ); 16 return 0; 17 } Hello world myputs str char str[20] char* str main 2 int main(void) { char str[20]; char* str2; } str str2 char str[20] char* str myput void myputs(char* str) { int i; for( i = 0; str[i]!= \0 ; i++ ) { putchar(str[i]); 132
142 6 } } printf("\n"); void myputs(char str[]) void myputs(char* str); void myputs(char str[20]); void myputs(char str[]); myputs( str ); myputs( &str[0] ) main char str[10000]; myputs int array[5] int 5 int* p[5] int*
143 6.7 3 int main(void) 4 { 5 int array[5] = {1, 2, 3, 4, 5}; 6 int* p[5]; 7 int i; 8 9 for(i = 0; i < 5 ; i++) { 10 p[i] = &array[i]; 11 printf("p[%d] : %p\n", i, p[i]); 12 } *p[0] += 10; for(i = 0; i < 5 ; i++) { 17 printf("*p[%d] : %d\n", i, *p[i]); 18 } 19 } for array[i] p[i] p[i] 6.15 for p[0] : 100 p[1] : 104 p[2] : 108 p[3] : 112 p[4] : 116 *p[0] += 10 p[0] array[0] 10 for *p[i] p[i] 134
144 6 6.15: p[0] : 100 p[1] : 104 p[2] : 108 p[3] : 112 p[4] : 116 *p[0] : 11 *p[1] : 2 *p[2] : 3 *p[3] : 4 *p[4] :
145 int main(void) 4 { 5 char* str = "Hello"; 6 printf("%s\n", str ); 7 8 return 0; 9 } Hello 6.16 str 6.16: char* str = "Hello" char str2[10] = "Hello" 6.17 str char str2 136
146 6 6.17: 2 3 int main(void) 4 { 5 char* str = "Hello"; 6 char str2[10] = "Hello"; 7 8 str[0] = B ; /* */ 9 str2[0] = B ; /* OK */ return 0; 12 } str[0] *(str + 0) str str[0] = B str2 137
147 char int char* int* 2 3 int main(void) 4 { 5 int hoge = 10; 6 int* p_hoge; 7 int** p_p_hoge; 8 9 p_hoge = &hoge; 10 p_p_hoge = &p_hoge; printf("hoge = %d\n", hoge); 13 printf("*p_hoge = %d\n", *p_hoge); 14 printf("p_hoge address = %p\n", &p_hoge); 15 printf("p_p_hoge = %p\n", p_p_hoge); 16 printf("**p_p_hoge = %d\n", **p_p_hoge); return 0; 19 } : 138
148 6 6.19: p hoge hoge p p hoge int* p p hoge p hoge hoge : **p p hoge *( *p p hoge ) *( p hoge ) hoge = 10 *p_hoge = 10 p_hoge address = 150 p_p_hoge = 150 **p_p_hoge =
149 strlen strlen my strlen my strlen 2 3 int my_strlen(const char* str) 4 { 5 int i = 0; 6 while( *str++ ) { 7 i++; 8 } 9 return i; 10 } int main(void) 13 { 14 char str[20] = "Hello world"; 15 printf("%s %d \n", str, my_strlen(str)); 16 return 0; 17 } const char* str my strlen str[i] = E ; *(str + i) = E ; *str++; *(str++); NULL NULL \0 0. while( 0 ) 140
150 strcat strcpy my strcpy 2 3 void my_strcpy(char* dest, const char* src) 4 { 5 while( *dest++ = *src++ ) 6 ; 7 } 8 9 int main(void) 10 { 11 char str[20] = "Hello world"; 12 char copy[20]; my_strcpy(copy, str); 15 printf(" %s \n",copy); 16 return 0; 17 } int main(void) 4 { 5 int hoge = 30; 6 int* piyo = &hoge; 7 8 printf("out1 :%d\n",hoge); 9 printf("out2 :%d\n",*piyo); 141
151 return 0; 12 } int main(void) 4 { 5 int x = 10; 6 int y = 20; 7 int* hoge = &x; 8 int* piyo = &y; 9 int* tmp; tmp = hoge; 12 hoge = piyo; 13 piyo = tmp; printf("out1 :%d\n",x); 16 printf("out2 :%d\n",*hoge); return 0; 19 } int main(void) 4 { 5 int array[5] = {1,2,3,4,5}; 6 int* p = &array[0]; 7 142
152 6 8 p += 2; 9 printf("out1 :%d\n",*p); return 0; 12 } int main(void) 4 { 5 int array[5] = { 1, 5, 10, 15, 20 }; 6 int* p; 7 8 p = &array[0]; 9 10 printf("%d %d %d %d %d\n",*(p+0), *(p+1), p[2], 3[p], *p ); 11 p = array; 12 printf("%d %d %d %d %d\n",*(p+0), *(p+1), p[2], 3[p], *p ); *p += 10; 15 printf("p[0] : %d\n",p[0]); (*p)++; 18 printf("*p : %d\n",*p); *(p++); 21 printf("*p : %d\n",*p); 22 }
153 int main(void) 4 { 5 char* p = "Hello world"; 6 7 printf("%s\n",p); 8 p[1] = a ; 9 printf("%s\n",p); return 0; 12 } 6 hoge 100 i 200 j 300 k int main(void) 4 { 5 int hoge = 10; 6 int* i = &hoge; 7 int** j = &i; 8 int*** k = &j; 9 10 printf("hoge = %d\n", hoge); 11 printf("&hoge= %p\n", &hoge); 12 printf("*i = %d\n", *i); 13 printf("&i = %p\n", &i); 14 printf("&j = %p\n", &j); 15 printf("*j = %p\n", *j); 16 printf("**j = %d\n", **j); 17 printf("k = %p\n", k); 18 printf("*k = %p\n", *k); 19 printf("**k = %p\n", **k); 20 printf("***k = %d\n", ***k); return 0; 23 } 144
154 struct { }; 2 3 #define NUMBER_OF_STUDENT struct Student{ 6 char student_name[100]; 7 int student_age; 8 }; 9 10 int main(void) 11 { 12 struct Student st[number_of_student]; 13 int i; 14 int num; 15 printf("%d \n",number_of_student); for( i=0; i < NUMBER_OF_STUDENT ; i++ ) { 18 printf("%d :",i+1); 19 scanf("%s",st[i].student_name); 20 printf("%d :",i+1);
155 scanf("%d",&st[i].student_age); 22 } for(;;) { 25 printf(" :"); 26 scanf("%d",&num); if( num > NUMBER_OF_STUDENT num <= 0) { 29 printf(".\n"); 30 break; /* */ 31 } else { 32 printf(" : %s, : %d\n",st[num-1].student_name, 33 st[num-1].student_age); 34 } 35 } 36 return 0; 37 } struct Student st[number_of_student]; Student NUMBER_OF_STUDENT st[0].student_name 146
156 7 3 1 :nishio 1 :20 2 :itoh 2 :20 3 :yamada 3 :33 :2 : itoh, : 20 :1 : nishio, : 20 :3 : yamada, : 33 : int int int* hoge; struct Student{ char student_name[100]; int student_age; }; Student struct Student* hoge; hoge hoge hoge->student_age -> - ( > 147
157 7.2 (*hoge).student_age hoge student_age *hoge.student_age (*hoge).student_age ( 7.2) *(hoge.student_age) 7.1: ( ) [ ] ->.! ~ ++ == = * sizeof * / + - << >> < <= > >= ==!=? = += -= *= /=, 148
158 7 7.3 typedef typedef typedef ; unsigned int typedef tyepdef unsigned int uint; unsigned int uint typedef 2 3 #define NUMBER_OF_STUDENT typedef struct Student_tag{ 6 char student_name[100]; 7 int student_age; 8 } Student; 9 10 int main(void) 11 { 12 Student st[number_of_student]; 13 int i; 14 int num; 15 printf("%d \n",number_of_student); for( i=0; i < NUMBER_OF_STUDENT ; i++ ) { 18 printf("%d :",i+1); 19 scanf("%s",st[i].student_name); 20 printf("%d :",i+1); 21 scanf("%d",&st[i].student_age); 22 } for(;;) { 25 printf(" :"); 149
159 scanf("%d",&num); if( num > NUMBER_OF_STUDENT num <= 0) { 29 printf(".\n"); 30 break; /* */ 31 } else { 32 printf(" : %s, : %d\n",st[num-1].student_name, 33 st[num-1].student_age); 34 } 35 } 36 return 0; 37 } 12 struct Student_tag st[number_of_student]; typedef typedef struct typedef struct Student_tag{ char student_name[100]; int student_age; } Student;, Student p1(x 1, y 1 ), p2(x 2, y 2 ) 2 2 d d = (x 2 x 1 ) 2 + (y 2 y 1 ) 2 2 #include <math.h> 3 150
160 7 4 typedef struct Point_tag{ 5 double x; 6 double y; 7 } Point; 8 9 int main(void) 10 { 11 Point p1, p2; 12 double distance; printf("p1 (x,y) :"); 15 scanf("%lf %lf", &p1.x, &p1.y); printf("p2 (x,y) :"); 18 scanf("%lf %lf", &p2.x, &p2.y); distance = sqrt( (p2.x - p1.x) * (p2.x - p1.x) + 21 (p2.y - p1.y) * (p2.y - p1.y) ); 22 printf("2 : %f\n", distance ); 23 return 0; 24 } 151
161
162 C malloc 2 3 int main(void) 4 { 5 int buf[10]; 6 int number, i, sum; 7 8 printf(" : "); 9 scanf("%d", &number); for(i = 0; i < number; i++) { 12 printf("%d :", i+1); 13 scanf("%d", &buf[i] ); 14 } for(i = 0, sum = 0; i < number; i++ ) { 17 sum += buf[i]; 18 } printf(" : %d\n", sum); 21 return 0; 22 }
163 8.1 buf int buf[1000]; malloc stdlib.h = malloc( ); malloc 1 NULL free free( ); int 5 int* p; p = (int *)malloc( 4 * 5 ); if(!p ) { printf(" \n"); exit(1); /* */ } int 4 int 5 20bytes ( 8.1) int 4 int sizeof 1 malloc 154
164 8 8.1: p = (int *)malloc( sizeof(int) * 5 ); malloc 2 #include <stdlib.h> 3 4 int main(void) 5 { 6 int* buf; 7 int number, i, sum; 8 9 printf(" : "); 10 scanf("%d", &number); buf = (int *)malloc( number * sizeof(int) ); if(!buf ) { 15 printf(" \n"); 16 exit(1); 17 } for(i = 0; i < number; i++) { 155
165 printf("%d :", i+1); 21 scanf("%d", &buf[i] ); 22 } for(i = 0, sum = 0; i < number; i++ ) { 25 sum += buf[i]; 26 } printf(" : %d\n", sum); 29 free( buf ); 30 return 0; 31 } exit : 5 1 :1 2 :2 3 :3 4 :4 5 :5 : C 156
166 FILE fopen FILE* fp = fopen(char*, char* ); stdio.h fopen FILE FILE : r w a rb wb ab r+ / w+ / a+ / r fopen NULL w a ASCII Windows \n \r\n UNIX OS \n C OS 157
167 8.2 fclose fclose( FILE* ); 2 #include <stdlib.h> 3 4 int main() 5 { 6 char filename[100]; 7 FILE *fp; 8 9 printf(" :"); 10 scanf("%s", filename); fp = fopen(filename, "r"); 13 if (fp == NULL) { 14 printf(" \n"); 15 exit (1); 16 } 17 printf(" \n"); fclose(fp); 20 return 0; 21 } fgetc int fgetc(file* ); 158
168 8 fgetc unsigned char 1 int testfile.txt hello world #include <stdlib.h> 3 4 int main() 5 { 6 char filename[100] = "testfile.txt"; 7 FILE *fp; 8 int ch; 9 10 fp = fopen(filename, "r"); 11 if (fp == NULL) { 12 printf(" \n"); 13 exit (1); 14 } for(;;) { 17 ch = fgetc( fp ); 18 if( ch == EOF ) { 19 break; 20 } 21 printf("%c", ch); 22 } 23 printf("\n"); fclose(fp); 26 return 0; 27 } 159
169 8.2 hello world 363 fgetc ch EOF 2 EOF fgetc 1 fgets char* fgets(char* int, FILE* ); fgets 1 fgets -1 NULL fgets 2 #include <stdlib.h> 3 4 #define BUFSIZE int main() 7 { 8 char filename[100] = "testfile.txt"; 9 char buf[bufsize]; 10 FILE *fp; fp = fopen(filename, "r"); 13 if (fp == NULL) { 14 printf(" \n"); 15 exit (1); 16 } while( fgets( buf, BUFSIZE, fp )!= NULL ) { 2 End of File 160
170 8 19 printf("%s", buf); 20 } 21 printf("\n"); 22 fclose(fp); 23 return 0; 24 } fgets fscanf scanf int fscanf(file*, char*,...); EOF fscanf 2 #include <stdlib.h> 3 4 #define BUFSIZE int main() 7 { 8 char filename[100] = "testfile.txt"; 9 char buf[bufsize]; 10 FILE *fp; fp = fopen(filename, "r"); 13 if (fp == NULL) { 14 printf(" \n"); 15 exit (1); 16 } while( fscanf( fp, "%s", buf )!= EOF ) { 19 printf("%s\n", buf); 20 } 21 fclose(fp); 22 return 0; 23 } 161
171 fputc int fputc(int, FILE* ); hello out.txt 2 #include <stdlib.h> 3 4 int main() 5 { 6 char filename[100] = "out.txt"; 7 char buf[100] = "hello"; 8 FILE* fp; 9 int i; fp = fopen(filename, "w"); 12 if (fp == NULL) { 13 printf(" \n"); 14 exit (1); 15 } for( i = 0; buf[i]!= \0 ; i++ ) { 18 fputc( buf[i], fp ); 19 } 20 printf(" \n"); 21 fclose(fp); 22 return 0; 23 } w out.txt 162
172 8 fputs int fputs(char*, FILE* ); fputs EOF fputs 2 #include <stdlib.h> 3 4 int main() 5 { 6 char filename[100] = "out.txt"; 7 char buf[100] = "hello"; 8 FILE* fp; 9 10 fp = fopen(filename, "w"); 11 if (fp == NULL) { 12 printf(" \n"); 13 exit (1); 14 } if( fputs( buf, fp )!= EOF ) { 17 printf(" \n"); 18 }else { 19 printf(" \n"); 20 } 21 fclose(fp); 22 return 0; 23 } fputs fprintf printf int fprintf(file*, char*,...); fprintf 163
173 8.2 2 #include <stdlib.h> 3 4 int main() 5 { 6 char filename[100] = "out.txt"; 7 char buf[100] = "hello"; 8 FILE* fp; 9 10 fp = fopen(filename, "w"); 11 if (fp == NULL) { 12 printf(" \n"); 13 exit (1); 14 } fprintf( fp, "%s", buf ); 17 printf(" \n"); 18 fclose(fp); 19 return 0; 20 } fgetc fgets EOF EOF. 3 #define EOF -1-1 EOF feof int feof(file* ); feof 0 0 textfile.txt feof
C V C 6 1 6.1.............................. 1 6.......................... 3 6.3..................... 5 6.4 NULL............................. 8 6.5......................... 9 6.6..............................
More informationmstrcpy 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 information1 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卒 業 研 究 報 告.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 informationOriginal : 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 informationuntitled
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 information10
2: http://www7.bpe.es.osaka-u.ac.jp/~kota/classes/jse.html kota@fbs.osaka-u.ac.jp 10 : 0 1 2 n 2 n 0 1 1 0 1 0 0 1 (2) = 105 1 = 8 1 2 8 = 256 0 9 105 i 106 j 256 2 1 #include int main(void)
More information‚æ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超初心者用
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 informationA/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 informationMinimum 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解きながら学ぶC++入門編
!... 38!=... 35 "... 112 " "... 311 " "... 4, 264 #... 371 #define... 126, 371 #endif... 369 #if... 369 #ifndef... 369 #include... 3, 311 #undef... 371 %... 17, 18 %=... 85 &... 222 &... 203 &&... 40 &=...
More informationohp03.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 informationuntitled
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 informationohp08.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 informationr08.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 information1 1 2 2 2.1 Java......... 2 2.2................................. 3 2.3.................................. 3 3 4 3.1....................................
06H082 1 1 2 2 2.1 Java......... 2 2.2................................. 3 2.3.................................. 3 3 4 3.1..................................... 4 3.2 GP.....................................
More informationr03.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 information3.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 <<
C++ C C++ 1 C++ C++ C C++ C C++? C C++ C *.c *.cpp C cpp VC C++ 2 C++ C++ C++ [1], C++,,1999 [2],,,2001 [3], ( )( ),,2001 [4] B.W. /D.M.,, C,,1989 C Web [5], http://kumei.ne.jp/c_lang/ 3 Hello World Hello
More information新版明解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: 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 information18 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 informationPowerPoint 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 informationdouble 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 information1 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新・明解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/* 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数値計算
プログラム作成から実行まで 数値計算 垣谷公徳 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 informationMicrosoft PowerPoint - CproNt02.ppt [互換モード]
第 2 章 C プログラムの書き方 CPro:02-01 概要 C プログラムの構成要素は関数 ( プログラム = 関数の集まり ) 関数は, ヘッダと本体からなる 使用する関数は, プログラムの先頭 ( 厳密には, 使用場所より前 ) で型宣言 ( プロトタイプ宣言 ) する 関数は仮引数を用いることができる ( なくてもよい ) 関数には戻り値がある ( なくてもよい void 型 ) コメント
More informationディジタル信号処理
http://www.cfme.chiba-u.jp/~yama// C 言 語 におけるファイル 入 出 力 テキスト バイナリの 取 り 扱 い ( )..[4]% gcc Wall o hoge hoge.c..[5]%./hoge 1 : 1 2 : 2 3 : 3 4 : 0 6..[6]% (! )..[4]% gcc Wall o hoge hoge.c..[5]%!g gcc Wall
More information1 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 informationtuat1.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 informationjoho07-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: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 informationlexex.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 informationII ( ) 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 informationC¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç
C (3) if else switch AND && OR (NOT)! 1 BMI BMI BMI = 10 4 [kg]) ( [cm]) 2 bmi1.c Input your height[cm]: 173.2 Enter Input your weight[kg]: 60.3 Enter Your BMI is 20.1. 10 4 = 10000.0 1 BMI BMI BMI = 10
More information1 1 2 2 2.1................................................ 2 2.2......................................... 2 3 Battle Ship 3 3.1......................
2013 10H071 1 1 2 2 2.1................................................ 2 2.2......................................... 2 3 Battle Ship 3 3.1............................................ 3 3.2............................................
More informationex12.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スライド タイトルなし
ファイル入出力 (2) これまでのおさらい ( 入出力 ) これまでの入出力は 入力 scanf 出力 printf キーボードと画面 ( 端末 ) scanf/printf は 書式つき入出力 フォーマットを指定する 標準入出力を対象とする 何もしなければ 標準入出力は キーボードと画面 ストリームという考え方 ストリーム (stream) = データの列 キーボードから打つ文字列 画面に出力される文字列
More informationI. 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 informationr07.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 informationPC 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 informationohp07.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 informationPowerPoint プレゼンテーション
プログラミング初級 第 13 回 2017 年 7 月 10 日 標準ライブラリ関数 1 標準ライブラリ関数とは 関数には (1) 自分で作る関数 (2) はじめから用意されている関数特に C 言語用用意されているもの : 標準ライブラリ関数 文字列の代入文字列の長さを求める文字列の比較文字列の連結 strcpy strlen strcmp strcat 2 文字列の操作 - 具体例を通して (141
More informationARM 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+ +
+ + 2 1 1 1.1................................ 1 1.2........................... 2 1.3............................. 2 1.4 ( ).................. 2 1.5........................ 3 1.6...................... 3
More informationI. 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 information1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main
C 2007 5 29 C 1 11 2 2.1 main() 1 FORTRAN C main() main main() main() 1 return 1 1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return
More informationtuat2.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 information1-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 informationprogram.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ファイル入出力
C プログラミング Ⅱ の基礎 とは ファイルへデータを書き込んだり ( 出力 ), ファイルからデータを読み込んだり ( 入力 ) する C 言語では キーボードからの入力 画面への出力と同じようなコードで 処理を実現できる プログラム 入力 出力 ファイル 出力 入力 2 入出力の基本 ストリーム プログラム上で様々な装置への入出力を行う機構様々な入出力装置を統一的な方法で扱うことができる ハードディスクなどではファイルデータによって入出力が行われる
More informationJava updated
Java 2003.07.14 updated 3 1 Java 5 1.1 Java................................. 5 1.2 Java..................................... 5 1.3 Java................................ 6 1.3.1 Java.......................
More informationファイル入出力
C プログラミング Ⅱ の基礎 とは ファイルへデータを書き込んだり ( 出力 ), ファイルからデータを読み込んだり ( 入力 ) する C 言語では キーボードからの入力 画面への出力と同じようなコードで 処理を実現できる プログラム 入力 出力 ファイル 出力 入力 2 入出力の基本 ストリーム プログラム上で様々な装置への入出力を行う機構様々な入出力装置を統一的な方法で扱うことができる ハードディスクなどではファイルデータによって入出力が行われる
More informationpptx
iphone 2010 8 18 C xkozima@myu.ac.jp C Hello, World! Hello World hello.c! printf( Hello, World!\n );! os> ls! hello.c! os> cc hello.c o hello! os> ls! hello!!hello.c! os>./hello! Hello, World!! os>! os>
More informationuntitled
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: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 informationI 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新・明解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 informationex14.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 informationMicrosoft Word - Cプログラミング演習(8)
第 8 回 (6/11) プログラミングスタイルなど [1] 名前のつけかた グローバル変数にはわかりやすい名前を, ローカル変数には短い名前を 関連性のあるものには関連性のある名前をつけて, 統一しよう 関数には能動的な名前を 名前は的確に 例題 1 次のコードの名前と値の選び方についてコメントせよ? #define TRUE 0? #define FALSE 1?? if ((ch = getchar())
More informationC ( ) 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 informationMicrosoft 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 informationK227 Java 2
1 K227 Java 2 3 4 5 6 Java 7 class Sample1 { public static void main (String args[]) { System.out.println( Java! ); } } 8 > javac Sample1.java 9 10 > java Sample1 Java 11 12 13 http://java.sun.com/j2se/1.5.0/ja/download.html
More information/ 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 informationC言語によるアルゴリズムとデータ構造
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(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
3 3 1. 1 (K&R.9) ~, &,, >>,
More information橡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 informationMicrosoft Word - C.....u.K...doc
C uwêííôöðöõ Ð C ÔÖÐÖÕ ÐÊÉÌÊ C ÔÖÐÖÕÊ C ÔÖÐÖÕÊ Ç Ê Æ ~ if eíè ~ for ÒÑÒ ÌÆÊÉÉÊ ~ switch ÉeÍÈ ~ while ÒÑÒ ÊÍÍÔÖÐÖÕÊ ~ 1 C ÔÖÐÖÕ ÐÊÉÌÊ uê~ ÏÒÏÑ Ð ÓÏÖ CUI Ô ÑÊ ÏÒÏÑ ÔÖÐÖÕÎ d ÈÍÉÇÊ ÆÒ Ö ÒÐÑÒ ÊÔÎÏÖÎ d ÉÇÍÊ
More informationO(N) ( ) log 2 N
2005 11 21 1 1.1 2 O(N) () log 2 N 1.2 2 1 List 3-1 List 3-3 List 3-4? 3 3.1 3.1.1 List 2-1(p.70) 1 1 10 1 3.1.2 List 3-1(p.70-71) 1 1 2 1 2 2 1: 1 3 3.1.3 1 List 3-1(p.70-71) 2 #include stdlib.h
More information3 3.1 LAN ISDN (IP) 2 TCP/UDP IP IP IP IP (Ethernet) Ethernet LAN TCP/UDP LAN Ethernet LAN 2: Ethernet ATM, FDDI, LAN IP IP IP 3 IP 2 IP IP IP IP IP 3
IP 1 (IP) TCP/IP 1 2 2 1 LAN IP C IP 192.168.0.101 192.168.0.104 HUB 100Base-TX 100Mbps UTP Ethernet HUB 192.168.0.101 192.168.0.102 192.168.0.103 192.168.0.104 1: 6 1 3 3.1 LAN ISDN (IP) 2 TCP/UDP IP
More information1.1 1 C IIA $ cd comp3a %endminipage ~/comp3a mkdir $ mkdir comp3a $ cd comp3a C.c Emacs Cntrol x Control s 2 Emacs Control-x Control-f Control-
1 C IIA 1 C IIA IIA 1.1 Mac OS X 1.1.1 Mac OS X Unicode(UTF-8) UTF-8 Jedit X( ) Emacs( ) Emacs Emacs Emacs [Finder] [] Emacs dock Jedit X C 1. Jedit X Dock drag & drop Jedit X [Finder] [] Jedit X Folder
More informationprog-text.dvi
(C ) 2008 1 2008.8.7 8 1 E mail : sakkun@yokohama-cu.ac.jp 3 I 13 1 17 1.1.......................... 17 1.1.1.......................... 17 1.1.2 OS................ 17 1.2..............................
More informationコンピュータ概論
4.1 For Check Point 1. For 2. 4.1.1 For (For) For = To Step (Next) 4.1.1 Next 4.1.1 4.1.2 1 i 10 For Next Cells(i,1) Cells(1, 1) Cells(2, 1) Cells(10, 1) 4.1.2 50 1. 2 1 10 3. 0 360 10 sin() 4.1.2 For
More information[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:
005 9 7 1 1.1 1 Hello World!! 5 p r i n t f ( H e l l o World!! \ n ) ; 7 return 0 ; 8 } 1: 1 [ ] Hello World!! from Akita National College of Technology. 1 : 5 p r i n t f ( H e l l o World!! \ n ) ;
More information第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ディジタル信号処理
信号処理論 ディジタル画像処理 C 言語におけるファイル入出力 テキスト バイナリの取り扱い ( )..[4]% gcc Wall o hoge hoge.c..[5]%./hoge 1 : 1 2 : 2 3 : 3 4 : 0 6..[6]% (! )..[4]% gcc Wall o hoge hoge.c..[5]%!g gcc Wall o hoge hoge.c..[6]%!! gcc
More information計算機プログラミング
プログラミング言語 C 第 8 講 システム標準関数 ( 入出力関数 ) システム標準関数 システムに備え付けの関数 例 ) printf( ); scanf( ); 標準出力関数 標準入力関数 A. 入出力用の関数 高水準入出力関数 高水準言語 (OS に依存しない ) 低水準入出力関数 機械語レベル (OS に依存 ) B. それ以外の関数 引数と関数の型 ( 戻り値 ) に注目しましょう 例
More informationDA100データアクイジションユニット通信インタフェースユーザーズマニュアル
Instruction Manual Disk No. RE01 6th Edition: November 1999 (YK) All Rights Reserved, Copyright 1996 Yokogawa Electric Corporation 801234567 9 ABCDEF 1 2 3 4 1 2 3 4 1 2 3 4 1 2
More informationPowerPoint プレゼンテーション
プログラミング応用演習 第 3 回構造体, ファイル入出力 先週の出席確認へのコメント 暗号を破りたいが 平文の候補が多すぎる 人間の目で確認する代わりに どんなプログラムがあればよいか? 辞書を挙げた人が多かった 正しい着眼です 何億個もの平文候補が想定されるので 形態素解析や品詞判別を挙げた人もいます 辞書に近い回答で悪くはないのですが 平文候補ごとにあまり高機能なものを呼び出すと時間がかかる
More information練習&演習問題
練習問題 ファイル入出力 練習問題 1 ファイルへのデータ出力 配列 a[ ] の値をファイル data.txt に出力するプログラムを作成しなさい #include #include /* srand(), rand() */ #include /* time() */ int main(void) { int i; double a[5];
More informationMicrosoft PowerPoint pptx
情報処理 Ⅱ 第 12 13回 2011 年 1 月 31 17 日 ( 月 ) 本日学ぶこと ファイル入出力, 標準入力 標準出力 記憶域管理関数 (malloc など ) 問題 ファイルを入力にとり, 先頭に行番号をつけて出力できる? 行列の積を, ファイルを介して読み書き 計算できる? Wakayama University./line 1:Wakayama 2:University 3 2
More informationdouble 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
C++ 1 C C++ C++ C C C++ 1.1 C printf() scanf() C++ C 1-1 #include int a; scanf( "%d", &a ); printf( "a = %d\n", a ); C++ 1-2 int a; std::cin >> a; std::cout
More information64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved
(Version: 2013/5/16) Intel CPU (kashi@waseda.jp) 1 Intel CPU( AMD CPU) 64bit SIMD Inline Assemler Windows Visual C++ Linux gcc 2 FPU SSE2 Intel CPU double 8087 FPU (floating point number processing unit)
More informationInformatics 2014
C 計算機の歴史 手回し計算機 新旧のソロバン バベッジの階差機関 スパコン ENIAC (1946) パソコン 大型汎用計算機 電卓 現在のコンピュータ Input Output Device Central Processing Unit I/O CPU Memory OS (Operating System) OS Windows 78, Vista, XP Windows Mac OS X
More informationPowerPoint Presentation
ファイルの入出力 芝浦工業大学情報工学科 青木義満 今回の講義内容 ファイル入出力 ファイルからのデータ読込み ファイルと配列 2 1 ファイルへのデータ書き込み ( 復習 ) ソースファイル名 :fileio1.c データをファイルに書き込み #include int main(void) { ファイルポインタ宣言 int student_id = 100; char name[
More informationvoid 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 >=
II 14 2018 7 26 : : proen@mm.ics.saitama-u.ac.jp 14,, 8 2 12:00 1 O(1) n O(n) O(log n) O(1) 32 : 1G int 4 250 M 2.5 int 21 2 0 100 0 100 #include #define HASHSIZE 100 /* */ #define NOTFOUND 0
More information目次
プログラミング I 第数理物理, 総合理学等向け 2018 年 11 月 24 日土 海谷治彦 1 目次 ファイルとは何か? プログラムからファイルを扱うには? ファイルの読み込み ファイルの書き込み ファイルの削除, 名称変更 2 電源を切ってもデータが残ってる! コンピュータの電源を切って再起動しても, データは残っている. ワードの文書,MP3 ファイル, 画像ファイル, プログラムファイル
More information‚æ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解きながら学ぶC言語
printf 2-5 37 52 537 52 printf("%d\n", 5 + 37); 5370 source program source file.c ex00.c 0 comment %d d 0 decimal -2 -p.6 3-2 5 37 5 37-22 537 537-22 printf("537%d\n", 5-37); function function call ( )argument,
More information1.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 informationC による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 新装版 1 刷発行時のものです.
C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. http://www.morikita.co.jp/books/mid/009383 このサンプルページの内容は, 新装版 1 刷発行時のものです. i 2 22 2 13 ( ) 2 (1) ANSI (2) 2 (3) Web http://www.morikita.co.jp/books/mid/009383
More information10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV
tutimura@mist.i.u-tokyo.ac.jp kaneko@ipl.t.u-tokyo.ac.jp http://www.misojiro.t.u-tokyo.ac.jp/ tutimura/sem3/ 2002 11 20 p.1/34 10/16 1. 10/23 2. 10/30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20
More informationJava Java Java Java Java 4 p * *** ***** *** * Unix p a,b,c,d 100,200,250,500 a*b = a*b+c = a*b+c*d = (a+b)*(c+d) = 225
Java Java Java Java Java 4 p35 4-2 * *** ***** *** * Unix p36 4-3 a,b,c,d 100,200,250,500 a*b = 20000 a*b+c = 20250 a*b+c*d = 145000 (a+b)*(c+d) = 225000 a+b*c+d = 50600 b/a+d/c = 4 p38 4-4 (1) mul = 1
More information2004 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 informationchar int float double の変数型はそれぞれ 文字あるいは小さな整数 整数 実数 より精度の高い ( 数値のより大きい より小さい ) 実数 を扱う時に用いる 備考 : 基本型の説明に示した 浮動小数点 とは数値を指数表現で表す方法である 例えば は指数表現で 3 書く
変数 入出力 演算子ここまでに C 言語プログラミングの様子を知ってもらうため printf 文 変数 scanf 文 if 文を使った簡単なプログラムを紹介した 今回は変数の詳細について習い それに併せて使い方が増える入出力処理の方法を習う また 演算子についての復習と供に新しい演算子を紹介する 変数の宣言プログラムでデータを取り扱う場合には対象となるデータを保存する必要がでてくる このデータを保存する場所のことを
More information2009 T060050
T060050 C++ Microsoft Visual C++ 2008 Express Edition DX C DX VC++ Debug exe 1 2 2009 T060050 1 1 2 1 2.1...................... 1 2.2....................... 2 3 3 3.1................... 3 3.2.....................
More informationI 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問 2 ( 型変換 ) 次のプログラムを実行しても正しい結果が得られない 何が間違いかを指摘し 正しく修正せよ ただし int サイズが 2 バイト long サイズが 4 バイトの処理系での演算を仮定する #include <stdio.h> int main( void ) { int a =
問 1 配列の宣言整数型配列 data1 にデータが初期設定されている この配列 data1 のデータを下図のように 整数型配列 data2 に代入しなさい また data2 の内容を printf( "data2[0] = %d\n", data2[0] ); printf( "data2[5] = %d\n", data2[5] ); を用いて出力しなさい 実行結果 data2[0] = 76
More information