C B

Similar documents
ii

パソコン機能ガイド

パソコン機能ガイド

Javaと.NET

2004年度日本経団連規制改革要望


™…

はしがき・目次・事例目次・凡例.indd

II

i




橡6.プログラム.doc

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

困ったときのQ&A


SC-85X2取説


<4D F736F F F696E74202D C835B B E B8CDD8AB B83685D>

エクセルカバー入稿用.indd


01_.g.r..

困ったときのQ&A

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

活用ガイド (ハードウェア編)

III


これわかWord2010_第1部_ indd

パワポカバー入稿用.indd

これでわかるAccess2010

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

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

第3章 OpenGL の基礎

untitled

i

2

I

平成18年版 男女共同参画白書

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

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

ohp03.dvi

Step2 入門

PowerPoint Presentation

Microsoft Word - 51プログラム名簿目次070913w.doc


01_SWGuide_V8.50.fm


結婚生活を強める

r07.dvi


ohp07.dvi

joho07-1.ppt

1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber();

vi アハ ート2 アハ ート3 アハ ート4 アハ ート5 アハ ート6 アハ ート7 アハ ート8 アハ ート9 アハ ート10 アハ ート11 アハ ート12 アハ ート13 アハ ート14 アハ ート15 アハ ート16 アハ ート17 アハ ート18 アハ ート19 アハ ート20 アハ

活用ガイド (ソフトウェア編)

r03.dvi



学習内容と日常生活との関連性の研究-まえがき・概要・目次

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

P06.ppt

VB-C50i/VB-C50iR 使用説明書

#include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> 4 Program 1 (OpenGL GameSample001) 5 // 6 static bool KeyUpON = false; // 7 sta

活用ガイド (ソフトウェア編)

‚æ4›ñ

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

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

活用ガイド (ソフトウェア編)

リファレンス

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

r08.dvi

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


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

SPP24_Program_WOC(J)-15

tuat1.dvi

『戦時経済体制の構想と展開』

ohp08.dvi

1 1. Program 1 OpenCV (OpenCV Sample001) 1 /* 2 - > - > - >VC++ 3 ( ) 4 C:\opencv\build\include 5 ( ) 6 C:\opencv\build\x86\vc10\lib 7 - > - > - > - >

ex12.dvi

ii

困ったときのQ&A

$ ls -l $ ls -l -a $ ls -la $ ls -F $ ls <dirname> <dirname> $ cd <dirname> <dirname> $ cd $ pwd $ cat <filename> <filename> $ less <filename> <filena


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

目次情報

(報告書まとめ 2004/03/  )


長崎県地域防災計画

橡Pro PDF

1.ppt

第3章 OpenGL の基礎

困ったときのQ&A

i


Wide Scanner TWAIN Source ユーザーズガイド

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

(search: ) [1] ( ) 2 (linear search) (sequential search) 1

C ontents VI VII

Transcription:

C 095707B 2010 6 8

1 LEVE1 2 1.1 LEVEL 1.1................................................ 2 1.1.1 1................................................ 2 1.1.2 1.2.............................................. 4 1.1.3 1.3.............................................. 5 1.2 LEVEL1.2... 6 1.3 LEVEL1.3... 7 2 LEVEL2 9 2.1 LEVEL2.1... 9 2.2 LEVEL2.2... 12 2.2.1................................ 12 2.2.2................................. 15 2.3 LEVEL2.3... 18 2.4 LEVEL2.4... 21 2.5 LEVEL2.5... 21 3 LEVEL3 24 3.1 LEVEL3.1... 24 3.2 LEVEL3.2... 26 4 27 1

1 LEVE1 1.1 LEVEL 1.1 1.2, 1.3 1.1.1 1. Pointer.c Pointer.c 01 #include <stdio.h> 02 03 #define ARRAY_SIZE 8 04 05 int main(int argc, char** argv) { 06 int i; 07 int array[array_size]; 08 int *int_pointer = array; 09 10 unsigned char *memory = (unsigned char*)array; 11 12 int\_pointer[0] = 0x00010203; 13 14 // 15 for(i=0; i<sizeof(array); i+=4) { 16 printf("%016lx: %02x %02x %02x %02x \n", 17 (long unsigned int)(memory+i), 18 memory[i], memory[i+1], memory[i+2], memory[i+3]); 19 } 20 return 0; 21 } Pointer.c 01 00000000bffff9b4: 03 02 01 00 02 00000000bffff9b8: c0 04 e0 8f 03 00000000bffff9bc: 0c f5 e2 8f 04 00000000bffff9c0: 04 00 00 00 05 00000000bffff9c4: 00 00 00 00 06 00000000bffff9c8: 00 00 00 00 07 00000000bffff9cc: bc 05 e0 8f 08 00000000bffff9d0: 00 00 00 00 2

< > 1. Pointer.c (a) 03 ARRAY SIZE=8 (b) 0608 i. 07 ii..array int pointer (c) 10 unsigned (d) 10 int array char array memory (e) 12 00010203 2. 1519 (a) 15 i sizeof(array) (b) 15 i=+4 int byte +4 (c) 17 memory int (d) 18 memory 3. 4. 01 5. memory 6. 3

1.1.2 1.2 Pointer.c int Pointer.c 10 int_pointer[0] = 0x00010203; 11 *(int_pointer+1) = 0xFF000001; 12 *(int_pointer+2) = 0xFF000002; 13 14 // 01 00000000bffff9b4: 03 02 01 00 02 00000000bffff9b8: 01 00 00 ff 03 00000000bffff9bc: 02 00 00 ff 04 00000000bffff9c0: 04 00 00 00 05 00000000bffff9c4: 00 00 00 00 06 00000000bffff9c8: 00 00 00 00 07 00000000bffff9cc: bc 05 e0 8f Pointer.c < > 1. (a) 11,12 (b) 11 int pointer 0xFF000001 (c) 12 int pointer 0xFF000002 (d) int pointer int 2. 02,03 3. 0xFF00000100000000bffff9b400000000bffff9b8 4. 0xFF00000200000000bffff9b400000000bffff9bc 5. int n 4n 6. int 4

1.1.3 1.3 Pointer.c unsigned char 1 12 *(int_pointer+2) = 0xFF000002; 13 *( memory + 5) = 0xee; 14 *( memory + 6) = 0xdd; 15 16 // 01 00000000bffff9b4: 03 02 01 00 02 00000000bffff9b8: 01 ee dd ff 03 00000000bffff9bc: 02 00 00 ff 04 00000000bffff9c0: 04 00 00 00 05 00000000bffff9c4: 00 00 00 00 06 00000000bffff9c8: 00 00 00 00 07 00000000bffff9cc: bc 05 e0 8f 08 00000000bffff9d0: 00 00 00 00 Pointer.c Pointer < > 1.. (a) 13,14 (b) 13 memory ee (c) 14 memory ff (d) memory unsigned char 2. 02 3. memory 00000000bffff9b4 (a) memory ee (b) ee00000000bffff9b9 (c) memory ff (d) ff00000000bffff9ba 4. unsigned char n n 5. unsigned char 5

1.2 LEVEL1.2 1.2 1. 2 1 /Intel 2. 2 1 /Motorola 3. 11.2 4. / 6

1.3 LEVEL1.3 (printf add sub.c 01 #include<stdio.h> 02 // 03 int add(int x, int y) 04 { 05 return x + y; 06 } 07 08 // 09 void add_sub(int x, int y, int *res_add, int *res_sub) 10 { 11 *res_add = x + y; 12 *res_sub = x - y; 13 } 14 15 16 int main(int argc, char** argv) 17 { 18 printf("add(%d, %d) = %d\n", 2, 3, add(2,3)); 19 20 int a,s; 21 add_sub(2, 3, &a, &s); 22 23 printf("add_sub(%d, %d, &a, &s)\n", 2, 3); 24 printf("add = %d\n", a); 25 printf("sub = %d\n", s); 26 } 01 add(2, 3) = 5 02 add_sub(2, 3, &a, &s) 03 add = 5 04 sub = -1 add sub.c < > 1.. (a) 0306 add 7

i. 03 int ii. 05 return (b) 0813 add sub i. ii. 09 int int iii. 11 res add iv. 12 res sub (c) 1626 main i. 18 add printf ii. 20 iii. 21 add sub a,s iv. 23 printf v. 24 a vi. 25 s 2. 01 add 3. 03 add sub 4. 04 add sub 8

2 LEVEL2 2.1 LEVEL2.1 callback.c 01 #include <stdio.h> 02 03 void DoCallback( int (*cbfunc)(int,int,int) ) // 04 //cbfunc int int 05 { 06 int ret = cbfunc(0, 1, 2); // 07 printf("callback function returned %d\n", ret); 08 } 09 10 int MyCallbackFunc1(int l, int c, int r) 11 { 12 printf("mycallbackfunc1 is called\n"); 13 return l+c+r; 14 } 15 16 int MyCallbackFunc2(int l, int c, int r) 17 { 18 printf("mycallbackfunc2 is called\n"); 19 return l-c-r; 20 } 21 22 int main() 23 { 24 DoCallback(MyCallbackFunc1); 25 DoCallback(MyCallbackFunc2); 26 } 01 MyCallbackFunc1 is called 02 callback function returned 3 03 MyCallbackFunc2 is called 04 callback function returned -3 callback.c < > 1. (a) 0308 DoCollback i. 03 ii. 06 9

iii. 06 int ret cbfunc(0,1,2) iv. 07 ret (b) 1014 MyCollbackFunc1 i. ii. 10 int iii. 12 iv. 13 return (c) C.1620 MyCollbackFunc2 i. ii. 16 int iii. 18 iv. 19 return (d) 2226 main i. ii. 24 DoCallback iii. 24 MyCollbackFunc1 iv. 25 DoCallback v. 25 MyCollbackFunc2 2. 01,02 MyCollbackFunc1 3. 03,04 MyCollbackFunc2 4. 01 ///Main /// 02 ///DoCallback /// 03 ///MyCallbacFunc1 /// 04 MyCallbackFunc1 is called 05 ///DoCallback /// 06 callback function returned 3 07 ///Main /// 08 ///DoCallback /// 09 ///MyCallbacFunc1 /// 10 MyCallbackFunc2 is called 11 ///DoCallback /// 12 callback function returned -3 13 ///Main /// callback.c 5. (a) i. DoCollback 01 main 10

ii. cbfunc MyCollbackFunc1 02 DoCollback iii. 06 MyCollbackFunc1 02 DoCollback iv. MyCollbackFunc1 03,04 MyCollbackFunc1 v. int ret 05 DoCollback vi. 07 05 DoCollback vii. DoCollback 06 main viii. cbfunc MyCollbackFunc2 07 DoCollback ix. 06 MyCollbackFunc2 08 DoCollback x. MyCollbackFunc1 09,10 MyCollbackFunc2 xi. int ret 11 DoCollback xii. 07 12 DoCollback xiii. main return 13 main (b) DoCallback MyCallbackFunc 11

2.2 LEVEL2.2 1.3 # ## 2.2.1 callback3main.c 01 #include<stdio.h> 02 /* 03 "printf" 04 */ 05 06 void searchstring(char*); 07 08 int main(void) 09 { 10 searchstring("printf"); 11 12 return 0; 13 } callback3sub.c 01 /* 02 03 */ 04 05 #include <stdio.h> 06 #include <string.h> 07 08 #define BUF_SIZE 256 09 10 void searchstring(char* str) 11 { 12 char buf[buf_size]; 13 14 while(fgets(buf, BUF_SIZE, stdin)) { 15 /* strstr( 16 17. 18 NULL. 12

19 NULL 20 */ 21 if(strstr(buf, str)!= NULL) { 22 printf("%s", buf); 23 } 24 } 25 } 01 moano 02 n3e 03 printf 04 printf 05 fano 06 joeprintf 07 joeprintf 08 printmoe callback3main.c callback3sub.c < > 1..callback3Main.c (a) 06 (b) 0813 main (c) 10 searchstring (d) printf 2. callback3sub.c (a) (b) 08 BUF SIZE 256 (c) 1025 searchstring (d) 10 *char str (e) 14 (f) buf 256 (g) 1520 21 (h) 22 str (i) 3. 03,04 06,07 printf 4. printf 13

09 searchstring("#"); callback3main.c callback3sub.c 20 */ 21 char* s = strstr(buf,str); 22 if(s == buf) { 23 printf("%s", buf); 01 enova 02 printf 03 no#an 04 #noane 05 #noane 06 m3o# callback3main.c callback3sub.c < > 1..callback3Main.c 09 (a) # callback3main 09 (b) main 2. callback3sub.c 21 22 (a) (b) # # (c) 21 buf str s (d) 22 s buf (e) str (f) str 23 14

2.2.2 callback3bmain.c 01 #include <stdio.h> 02 #include <string.h> 03 04 /* 05 06 07 08 int (*callback)(char*) char* 09 */ 10 void searchwith(int (*callback)(char*) ); 11 12 /* 13 line printf 1 14 */ 15 int iscontainprintf(char* line) { 16 return strstr(line, "printf")!= NULL; 17 /* 18 if(strstr(line, "printf")!= NULL) 19 return 1; 20 else 21 return 0; 22 */ 23 } 24 25 /* (iscontainprintf) */ 26 int main(void) 27 { 28 searchwith(iscontainprintf); 29 30 return 0; 31 } callback3bsub.c 01 #include <stdio.h> 02 03 #define BUF_SIZE 256 04 05 /* 06 07 15

08 09 (int (*callback)(char*) ) char* 10 callback 11 12 callback 13 */ 14 void searchwith(int (*callback)(char*) ) 15 { 16 char buf[buf_size]; 17 while(fgets(buf, BUF_SIZE, stdin)) { 18 if(callback(buf)) { 19 printf("%s", buf); 20 } 21 } 22 } callback3bmain.c callback3bsub.c callback3main.c callback3sub.c < > 1. callback3bmain.c (a) (b) callback3bmain.c iscontainprintf main (c) 10 serchwith (d) 1523 iscontainprintf (e) 28 searchwith iscontainprintf 2. callback3bsub.c (a) (b) callback3bsub.c serchwith (c) 18 callback3bmain.c 15 int iscontainprintf(char* line) { 16 char* s = strstr(line,"#"); 17 return s == line; 18 /* 16

callback3bmain.c callback3bsub.c callback3main.c callback3sub.c < > 1. callback3bmain.c 17 18 2. # printf # 3. 16 line # s 4. 17 s line 5. # 6. callback3bsub.c 7. callback3bsub.c 17

2.3 LEVEL2.3 callback4bsub.c callback4bsub.c callback4main.c 01 #include <stdio.h> 02 03 int hasthree(int item); 04 05 /* */ 06 void printonfound(int item) 07 { 08 printf("%d is found.\n", item); 09 } 10 11 /* */ 12 void indicateonfound(int item) 13 { 14 int i; 15 putchar( [ ); 16 for(i=0; i<item; i++) { 17 putchar( * ); 18 } 19 puts("]"); 20 } 21 /**/ 22 int main(void) 23 { 24 int i=0; 25 int j=0; 26 int data1[] = {0,1,2,3,4,5,6,7,8,9,10,-1}; 27 int data2[] = {3,6,8,13,5,27,0,6,2,34,63,123,65,-1}; 28 29 while(1){ 30 int num = data2[i]; 31 if(hasthree(num)) 32 printonfound(num); 33 i++; 34 if(num == -1) break; 35 } 36 37 while(1){ 38 int num = data1[j]; 18

39 if(hasthree(num)) 40 indicateonfound(num); 41 j++; 42 if(num == -1) break; 43 } 44 45 return 0; 46 } callback4sub.c 01 include <stdio.h> 02 03 //3 04 int hasthree(int item) 05 { 06 return (item % 3 == 0 item % 10 == 3 item /10 == 3); 07 } 01 3 is found. 02 6 is found. 03 13 is found. 04 27 is found. 05 0 is found. 06 6 is found. 07 34 is found. 08 63 is found. 09 123 is found. 10 [] 11 [***] 12 [******] 13 [*********] callback4main.c callback4sub.c < > 1. callback4bmain.c (a) callback4bmain.c printonfound indicateonfound main (b) 03 hasthree (c) 0609 printonfound i. 19

ii. 06 int iii. 08 (d) 1220 indicateonfound i. ii. 12 int iii. 1618 * (e) 2246 main i. ii..2427 iii. 2935 pintonfound while iv. 30 i num v. 31 num 3 hathree vi. 32 printonfound vii. 34 numi -1 while viii. 3744 indicateonfound while ix. 3744 2935 2. callback4bsub.c (a) callback4bsub.c hasthree (b) 0407 hasthree i. 04 int ii. 06 3 0 10 3 10 iii. 3. (a) Sub (b) (c) main (d) Main 20

2.4 LEVEL2.4 Level2.3 callback4bmain.c maia main while while callback4bsub.c main main 2.5 LEVEL2.5 callback4bmain.c 01 #include <stdio.h> 02 03 void findnumber(int array[]); 04 void registercallback(int (*callback)(int) ); 05 06 07 int hasthree(int item) 08 { 09 return (item % 3 == 0 item % 10 == 3 item /10 == 3); 10 } 11 12 int hastwo(int item) 13 { 14 return (item % 2 == 0 item % 10 == 2 item /10 == 2); 15 } 16 17 /**/ 18 int main(void) 19 { 20 /* -1 */ 21 int data1[] = {0,1,2,3,4,5,6,7,8,9,10, -1}; 22 int data2[] = {3,6,8,13,5,27,0,6,2,34,63,123,65, -1}; 23 24 25 registercallback(hasthree); 26 27 findnumber(data1); 28 29 registercallback(hastwo); 21

30 31 findnumber(data2); 32 33 return 0; 34 } callback4bsub.c 01 #include <stdio.h> 02 03 static int (*onfoundfuncpointer)(int) = NULL; 04 05 void registercallback(int (*callback)(int) ) 06 { 07 onfoundfuncpointer = callback; 08 } 09 10 void findnumber(int array[]) 11 { 12 int i=0; 13 while(array[i]!= -1) { 14 if(onfoundfuncpointer(array[i]) ) { 15 printonfound(array[i]); 16 } 17 i++; 18 } 19 putchar( \n ); 20 } 21 22 int printonfound(int item) 23 { 24 printf("%d is found.\n", item); 25 } 22

01 0 is found. 02 3 is found. 03 6 is found. 04 9 is found. 05 13 06 6 is found. 07 8 is found. 08 27 is found. 09 0 is found. 10 6 is found. 11 2 is found. 12 34 is found. callback4bmain.c callback4bsub.c < > 1. callback4bmain.c (a) int 04 (void (*callback)(int) ); (int (*callback)(int) ); (b) 0710 (c) Main (d) 1215 (e) 0710 (f) 25 (printonfound) (hasthree) (g) 2931 2. callback4bsub.c (a) int 03 void (*onfoundfuncpointer) int (*onfoundfuncpointer) (b) int 05 (void (*callback)(int) ); (int (*callback)(int) ); (c) 14 hasthree(array[i]) onfoundfuncpointer(array[i]) (d) 15 onfoundfuncpointer(array[i]); printonfound(array[i]); (e) 2225 3. 4. Main Sub 5. void int 23

3 LEVEL3 3.1 LEVEL3.1 glut.c GLUT glut.c 01 #include <GLUT/glut.h> 02 #include <stdio.h> 03 04 // 05 void display(void) 06 { 07 printf("display\n"); 08 } 09 10 // 11 void mouse(int button, int state, int x, int y) 12 { 13 if(state == GLUT_UP) { 14 printf("mouse up\n"); 15 }else{ 16 printf("mouse down\n"); 17 } 18 } 19 20 // 21 void keyboard(unsigned char key, int x, int y) 22 { 23 printf("keyboard(%c)\n", key); 24 } 25 26 int main(int argc, char *argv[]) 27 { 28 glutinit(&argc, argv); //glut 29 glutcreatewindow(argv[0]); //window 30 31 // 32 glutdisplayfunc(display); //display 33 glutmousefunc(mouse); //mouse 34 glutkeyboardfunc(keyboard);//keyboard 35 36 glutmainloop(); // 37 printf("exit\n"); 38 return 0; 39 } 24

01 display 02 mouse down 03 mouse up 04 keyboard(a) 05 keyboard(o) 06 keyboard(3) 07 )eyboard( glut.c < > 1. glut.c (a) 0509 display i. display (b) 1118 mouse i. 13 GLUT UP mouse up ii. mouse down (c) 2124 keyboard i. ii. (d) 2639 main i. 2. (a) 01 glut.c 32 (b) 02,03 (c) glut.c 33 glutmousefunc (d) 0406 (e) glut.c 34glutKeyboardFunc (f) 07 return(enter) (g) return (h) 36 25

3.2 LEVEL3.2 1. GUI 2. 3. 4. 5. 6. 26

4 1. http://e-words.jp/w/e383aae38388e383abe382a8e383b3e38387e382a3e382a2e383b3.html 2. http://itpro.nikkeibp.co.jp/word/page/10000108/ http://www.weblio.jp/content/ 27