卒 業 研 究 報 告.PDF

Size: px
Start display at page:

Download "卒 業 研 究 報 告.PDF"

Transcription

1 C

2

3 Lisp Pascal Java Purl HTML Windows - 2-2

4 D.M. (Dennis M Ritchie) PDP-11 UNIX UNIX UNIX ++ Java ++ Java OS Windows Windows 2-2. UNIX VI Emacs Windows WordPad (1) (2) (3) - 3-3

5 2-3. (variable) (function) 1 (statement) { } (type) (formal parameter) _ main( ) main( ) main( { } (library function) ANSI C (C Standard library) BASIC Pascal printf( ) printf( ) printf( ) - 4-4

6 printf( ) 2 (string) printf( ) printf( ) (argument).h #include (preprocessor directive) (preprocessor) #include stdio.h #include <stdio.h> stdio.h printf( ) #include #include [prog -1] [prog2-2] #include <stdio.h> int main( ) { printf( Hello!! n ); return 0; } Hello!! [prog 2-1] [prog 2- ] - 5-5

7 1 #include <stdio.h> printf( ) 2 int main( main( ) 3 6 { } 4 printf( ) printf( ) 5 return 0; main( ) ( ) a b 0 n t? [prog 2-3] #include <stdio.h> void main() { int a=2, b=1, c, d; printf( a=%d b=%d n,a,b); c= a + b; d= a - b; printf( =%d =%d n, c, d); } [prog 2-3] a=2 b= a b 2 c=a+b d=a-b a c d - 6-6

8 main( ) void int return void int a, b, c, d; int a,b,c,d (Integer) int a,b,c; printf() printf( a=%d b=%d n,a,b) % a,b %d % d 10 % f 10 % c % s (type) _ - 7-7

9 C char int long float int double float float double char 1 short 2 int long float double 2 8 int int int short int long - 8-8

10 2-4. double double sin( ) cos( ) tan( ) sin cos tan log( ) logn( ) exp( ) sqrt( x ) pow( x, y ) x x x y [prog 2-4] #include < stdio.h > #include < math.h > void main( ) { double x= /4, y; y=sin(x); printf(" %f rad sin %f ", x, y); [prog 2-4] 2 #include <math.h> y = sqrt(x) y = sin(x) y = log(x) x y - 9-9

11 x [prog 2-5] [prog 2-4] #include < stdio.h > #include < math.h > #define PI void main( ) { double x, y; /* */ x = PI/4. ; /* */ y=sin(x); printf(" %f rad sin %f ", x, y); } [prog 2-4] 2 /* */ #define PI

12 (1) (3) (1) (2) (3) 3-2. fopen( ) fopen( ) FILE *fopen( char *filename, char *mode); fopen( ) FILE ( stdio.h ) fopen( ) FILE fp fopen( )

13 fp = fopen( test, r ); r (NULL ) r+ + (NULL ) w w+ + a a+ + r w a r fopen r+ w+ a+ fclose( ) fclose( ) int fclose( FILE *fp ) ; fclose( ) fclose( ) 0-1 [prog 5-3]

14 #include< stdio.h > #include< stdlib.h > void main( ) { char str[80] = n ; FILE *fp; char *p; } if(!(fp = fopen( test, w ))) // test {printf( n );exit(1);} p=str; // str while(*p) { } if(fputc(*p,fp)==-1) {printf( n );exit(1);} p++; fclose(fp); [prog 3-1] test test fopen [ ] FILE * fopen( char *,char * ); [ ] NULL

15 fclose [ ] int fclose( FILE * ); [ ] fopen EOF(-1) [ ] fgets fclose( ) ; [ ] char *fgets( char *, int, FILE * ); [ ] 1 ' 0' -1 NULL(0) r fopen [ ] char str[80]; fgets( str,80,fp); fputs [ ] int fputs( char *,FILE * ); [ ] w a fopen [ ] fputs("abcdef",fp) ; fgetc [ ] int fgetc( FILE * ); [ ] EOF r fopen

16 [ ] c = getc(fp); fputc [ ] int putc( int, FILE * ); [ ] w a fopen [ ] putc('a',fp); fscanf [ ] int fscanf( FILE *,char *, ); [ ] scanf scanf r fopen [ ] fscanf(fp,"%d",&dt); fprintf [ ] int( FILE *,char *, ) [ ] printf printf w a fopen [ ] fprintf(fp,"%8d n",dt); 3-4. (command-line argument)

17 main( ) main( argc argv argc argc 1 argv argv char *argv[ ]; [ ] main( ) argv argv[0] argv[1] [prog 5-1] #include< stdio.h > int main( int argc, char *argv[ ] ) { for(int a=0;a<=3;a++) printf( %s,argv[a] ); return 0; } [prog 3-2] argv 4 com a, b, c, d, [prog 5-2] A>com a b c d com a b c [prog 3--3] d argv[0]

18 (1) (2) (3) (4) (5) (1) ( 100 ) (2) (3)

19 (4) (5) ( 10 ) main( ) stdio.h string.h strlib.h char names numbers int val 1: #include<string.h> //for strcmp,strstr 2: #include<stdlib.h> //for exit 3: #define MAX 100 //MAX100 4: char names[max][20]; // MAX : char numbers[max][20]; // MAX : int val; // 7: 8: int menu(); // 9: void enter(); // 10: void search(); // 11: void save(); // 12: void load(); // 13: void append(); // main( ) int choice menu( ) switch do-while case 1 case 5 (1) (5) menu( ) case 6 main( ) 15: int main() 16: { 17: int choice; 18: 19: do 20: {

20 21: choice = menu(); //menu() switch() 22: switch(choice) 23: { 24: case 1: enter();break; 25: case 2: save();break; 26: case 3: append();break; 27: case 4: load();break; 28: case 5: search();break; 29: case 6: 30: printf(" break; 31: } 32: } while(choice!=6); 33: return 0; 34: } MENU ] 2] 3] 4] 5] 6] ] 6] menu( ) int select 49 scanf( ) menu( )

21 36: int menu() 37: { 38: int select; 39: 40: printf("-- MENU n 41: printf("1] n 42: printf("2] n 43: printf("3] n 44: printf("4] n 45: printf("5] n 46: printf("6] n 47: printf(" n 48: printf(" 1] 6] 49: scanf("%d",&select); 50: if(!(select==1 select==2 select==3 select==4 select==5 select==6)) 51: {printf(" exit(1);} 52: return select; 53: } aaa MENU ] 2] 3] 4] 5] 6] ] 6] aaa enter( )

22 Z enter( ) enter( ) 55: void enter() 56: { 57: for(val=0;val<max;val++) 58: { 59: printf(" MAX=100 n 60: printf(" z n 61: printf(" 62: scanf("%s",names[val]); 63: if(strcmp(names[val],"z")==0 strcmp(names[val],"z")==0) break; 64: printf(" 65: scanf("%s",numbers[val]); 66: } 67: if(val>=max) 68: printf(" n 69: } enter( ) 1] 6] (MAX = 100 ) z yamada xxxx (MAX = 100 ) z save( ) FILE fp int i enter( ) fprintf(

23 save( ) 93: void save() 94: { 95: FILE *fp; 96: int i; 97: 98: if(!(fp = fopen("p-file", "w"))) 99: {printf(" nexit(1);} 100: for(i=0; i<val; i++) 101: {fprintf(fp, "%-15s %5s n",names[i], numbers[i]);} 102: fclose(fp); 103: printf(" n 104: } save( ) 1] 6] append( ) save( ) 111 a append( ) 106: void append() 107: { 108: FILE *fp; 109: int i; 110: 111: if(!(fp = fopen("p-file", "a"))) 112: {printf(" nexit(1);} 113: for(i=0; i<val; i++) 114: {fprintf(fp, "%-15s %5s n",names[i], numbers[i]);} 115: fclose(fp); 116: printf(" n 117: }

24 append( ) 1] 6] 3 load( ) FILE val fp fscanf( ) 133 load( ) 119: void load() 120: { 121: FILE *fp; 122: val=0; 123: 124: if(!(fp = fopen("p-file", "r"))) 125: {printf(" nexit(1);} 126: printf(" n 127: printf(" n 128: while(fscanf(fp, "%s%s", names[val], numbers[val])!=-1) 129: { 130: printf("%-15s%5s n",names[val], numbers[val]); 131: val++; 132: } 133: fclose(fp); 134: } load( ) 1] 6] yamada tanaka kimura xxxx yyyy zzzz

25 search( ) FILE fp char word int i a scanf( ) while fscanf( ) while { } strstr( ) i 1 i 0 89 printf( ) 90 search( ) 71: void search() 72: { 73: FILE *fp; 74: char word[10]; 75: int i=0; 76: val=0; 77: 78: if(!(fp = fopen("p-file", "r"))) 79: {printf(" nexit(1);} 80: printf(" n 81: printf(" 10 82: scanf("%s",&word); 83: while(fscanf(fp, "%s%s", names[val], numbers[val])!=-1) 84: { 85: if(strstr(names[val],word) strstr(numbers[val],word)) 86: {printf("%-10s%5s n",names[val],numbers[val]);i=1;} 87: } 88: if(i==0) 89: printf(" n 90: fclose(fp); 91: } search( )

26 1] 6] 5 (10 ) yamada yamada xxxx 6 1] 6]

27 (1) (2) (3) (4) (5) (6) (7) (8) (1) (2) (3) (4) (1 ) (5) (6) (7) (8)

28 main( ) stdio.h strlib.h ctype.h conio,h CTRL_Z ASCII 26 1: #include<string.h> 2: #include<stdlib.h> // for exit 3: #include<ctype.h> 4: #include<conio.h> // for getche 5: #define CTRL_Z 26 // CTRL_Z ASCII 26 8 int select if else scanf( ) switch scanf( ) case 1 case 8 (1) (8) case default 1 9 6: int main(int ac,char *av[]) 7: { 8: int select; 9: /************** ( ) **************/ 10: if(ac==1) 11: { 12: printf(" 13: printf(" n 14: printf(" : printf(" MENU 16: printf(" : printf(" n 18: printf(" 19: printf("[ ] < >_< > n 20: printf(" n

29 21: printf(" 22: printf("[ ] < >_< > n 23: printf(" n 24: printf(" 25: printf("[ ] < >_< > n 26: printf(" n 27: printf(" 28: printf("[ ] < >_< > n 29: printf(" 1 n 30: printf(" 31: printf("[ ] < >_< >_< > n 32: printf(" 33: printf(" n 34: printf(" 35: printf("[ ] < >_< >_< > n 36: printf(" 37: printf(" n 38: printf(" 39: printf("[ ] < >_< >_< 2> n 40: printf(" 41: printf(" n 42: printf(" 43: printf("[ ] < >_< > n 44: printf(" n 45: printf(" : printf(" n 47: } 48: /************** ( ) **************/ 49: else 50: { 51: printf(" : printf(" MENU 53: printf(" : printf(" n 55: printf("1) n 56: printf("2) n 57: printf("3) n

30 58: printf("4) n 59: printf("5] n 60: printf("6] n 61: printf("7] n 62: printf("8] n 63: printf("9] n 64: printf(" : printf(" n 66: printf(" 1] 9] 67: scanf("%d",&select); 68: switch(select) 69: { (ac==1) ---- MENU [ ] < >_< > [ ] < >_< > [ ] < >_< > [ ] < >_< > 1 [ ] < >_< >_< > [ ] < >_< >_< > [ ] < >_< >_< 2> [ ] < >_< >

31 (!(ac==1)) ---- MENU ] 2] 3] 4] 5] 6] 7] 8] 9] ] 9] case 1 FILE fp1 char ch getchar( ) case 1 70: /***************** case 1 ******************/ 71: case 1: 72: FILE *fp1; 73: char ch1; 74: 75: if(!(ac==2)) 76: {printf("error01 [ ] < >_< > 77: exit(1);} 78: if(!(fp1=fopen(av[1],"w"))) 79: {printf("error01 80: exit(1);}

32 81: printf(" n 82: printf(" Ctrl + z n 83: getchar(); // 84: while((ch1=getche())!=ctrl_z) 85: { 86: fputc(ch1,fp1); 87: if(ferror(fp1)) 88: {printf("error01 nfclose(fp1); 89: exit(1);} 90: } 91: if(fclose(fp1)==-1) 92: {printf("error01 n 93: exit(1);} 94: printf(" n %s ",av[1]); 95: break; case 1 1] 9] CTRL + z Hello!! case 2 case 1 case 2 96: /****************** case 2 *****************/ 97: case 2: 98: FILE *fp2; 99: char ch2; 100: 101: if(!(ac==2)) 102: {printf("error02 [ ] < >_< > n 103: exit(1);}

33 104: if(!(fp2=fopen(av[1],"a"))) 105: {printf("error02 n 106: exit(1);} 107: printf(" n 108: printf(" Ctrl + z n 109: getchar(); // 110: while((ch2=getche())!=ctrl_z) 111: { 112: fputc(ch2,fp2); 113: if(ferror(fp2)) 114: {printf("error02 nfclose(fp2); 115: exit(1);} 116: } 117: if(fclose(fp2)==-1) 118: {printf("error02 n 119: exit(1);} 120: printf(" n %s ",av[1]); 121: break; case 2 1] 9] 2 CTRL + z Everyone!! case 3 FILE fp3 char ch for { } fgetc(fp3) fp3 putchar(ch3)

34 case 3 122: /******************* case 3 ********************/ 123: case 3: 124: FILE *fp3; 125: char ch3; 126: 127: if(!(ac==2)) 128: {printf("error03 [ ] < >_< > n 129: exit(1);} 130: if(!(fp3=fopen(av[1],"r"))) 131: {printf("error03 n 132: exit(1);} 133: printf(" %s n",av[1]); 134: for(;;) // 135: { 136: ch3=fgetc(fp3); 137: if(ch3==-1)break; 138: putchar(ch3); 139: } 140: if(fclose(fp3)==-1) 141: {printf("error03 142: exit(1);} 143: break; case 3 1] 9] 3 Hello!! Everyone!! case 4 FILE fp4 char ch

35 while while ((ch4=fgetc(fp4))!=-1) fp4 ch4 av[2] ch4 av[2] 161 printf( ) case 4 144: /******************* case 4 ******************/ 145: case 4: 146: FILE *fp4; 147: char ch4; 148: 149: if(!(ac==3)) 150: {printf("error04 [ ] < >_< > 151: exit(1);} 152: if(!(fp4=fopen(av[1],"r"))) 153: {printf("error04 154: exit(1);} 155: while((ch4=fgetc(fp4))!=-1) // fp4 av[2] 156: { 157: if(ch4==*av[2]) 158: {printf(" %s ",av[1],av[2]); 159: exit(1);} 160: } 161: printf(" %s ",av[1],av[2]); 162: if(fclose(fp4)==-1) 163: {printf("error04 164: exit(1);} 165: break; e case 4 1] 9] 4 e

36 case 5 FILE fp5a fp5b char ch feof( ) feof(fp5a) fp5a feof( ) while(!feof(fp5a)) ch5=fgetc(fp5a) feof ) printf( ) case 5 166: /******************** case 5 *********************/ 167: case 5: 168: FILE *fp5a, *fp5b; 169: char ch5; 170: 171: if(!(ac==3)) 172: {printf("error05 [ ] < >_< >_< > 173: exit(1);} 174: if((fp5a=fopen(av[1],"r"))==0) 175: {printf("error05 176: exit(1);} 177: if((fp5b=fopen(av[2],"w"))==0) 178: {printf("error05 179: exit(1);} 180: while(!feof(fp5a)) // 181: { 182: ch5=fgetc(fp5a); 183: if(ferror(fp5a)) 184: {printf("error05 185: exit(1);} 186: if(!feof(fp5a)) 187: fputc(ch5,fp5b); 188: if(ferror(fp5b)) 189: {printf("error

37 190: exit(1);} 191: } 192: if(fclose(fp5a)==-1) 193: {printf("error05 194: exit(1);} 195: if(fclose(fp5b)==-1) 196: {printf("error05 197: exit(1);} 198: printf(" %s %s ",av[1],av[2]); 199: break; A B case 5 1] 9] 5 A B case 6 FILE fp6a fp6b int bite char ch fseek( ) fseek(fp6a, 0, SEEK_END) fp6a ( ) 216 bite=ftell(fp6a) fp6a 217 bite while bite ( ) 1 2 while{ } fseek( ) fseek(fp6a,bite, SEEK_SET) fp6a bite fgetc( ) fp6a fputc( ) fp6b printf( ) case

38 200: /******************** case 6 *******************/ 201: case 6: 202: int bite; 203: char ch6; 204: FILE *fp6a, *fp6b; 205: 206: if(!(ac==3)) 207: {printf("error06 [ ] < >_< >_< > 208: exit(1);} 209: if(!(fp6a=fopen(av[1], "r"))) 210: {printf("error06 211: exit(1);} 212: if(!(fp6b=fopen(av[2], "w"))) 213: {printf("error06 214: exit(1);} 215: fseek(fp6a, 0, SEEK_END); //fp6a 216: bite=ftell(fp6a); 217: bite=bite-1; 218: while(bite>= 0) // fp6a fp6b 219: { 220: fseek(fp6a, bite, SEEK_SET); 221: ch6=fgetc(fp6a); 222: if(ferror(fp6a)) 223: {printf("error06 224: exit(1);} 225: fputc(ch6,fp6b); 226: if(ferror(fp6b)) 227: {printf("error06 228: exit(1);} 229: bite--; 230: } 231: if(fclose(fp6a)==-1) 232: {printf("error06 233: exit(1);} 234: if(fclose(fp6b)==-1) 235: {printf("error

39 236: exit(1);} 237: printf(" %s ",av[1],av[2]); 238: break; A B case 6 1] 9] 6 A B case 7 FILE fp7a fp7b fp7temp char ch feof( ) fgetc( ) while(!feof(fp7a)) ch5=fgetc(fp7a) feof( ) fputc( ) if(!feof(fp7a))fputc(ch7,fp7temp) p7temp ferror( ) printf( ) case 7 239: /********************* case 7 **********************/ 240: case 7: 241: FILE *fp7a, *fp7b, *fp7temp; 242: char ch7; 243: 244: if(!(ac==3)) 245: {printf("error07 [ ] < >_< 1>_< 2> 246: exit(1);} 247: if(!(fp7a=fopen(av[1], "r"))) 248: {printf("error : exit(1);}

40 250: if(!(fp7b=fopen(av[2],"r"))) 251: {printf("error : exit(1);} 253: if(!(fp7temp=fopen("temp", "w"))) 254: {printf("error07 255: exit(1);} 256: while(!feof(fp7a)) // fp7a fp7temp 257: { 258: ch7=fgetc(fp7a); 259: if(ferror(fp7a)) 260: {printf("error07 261: exit(1);} 262: if(!feof(fp7a))fputc(ch7,fp7temp); 263: if(ferror(fp7temp)) 264: {printf("error07 265: exit(1);} 266: } 267: if(fclose(fp7a)==-1) 268: {printf("error07 269: exit(1);} 270: if(!(fp7a=fopen(av[1], "w"))) 271: {printf("error : exit(1);} 273: while(!feof(fp7b)) // fp7b fp7a 274: { 275: ch7=fgetc(fp7b); 276: if(ferror(fp7b)) 277: {printf("error07 278: exit(1);} 279: if(!feof(fp7b)) fputc(ch7,fp7a); 280: if(ferror(fp7a)) 281: {printf("error07 282: exit(1);} 283: } 284: if(fclose(fp7b)==-1) 285: {printf("error

41 286: exit(1);} 287: if(fclose(fp7temp)==-1) 288: {printf("error07 289: exit(1);} 290: if(!(fp7b=fopen(av[2], "w"))) 291: {printf("error : exit(1);} 293: if(!(fp7temp=fopen("temp", "r"))) 294: {printf("error07 295: exit(1);} 296: while(!feof(fp7temp)) // fp7temp fp7b 297: { 298: ch7=fgetc(fp7temp); 299: if(ferror(fp7temp)) 300: {printf("error07 301: exit(1);} 302: if(!feof(fp7temp)) fputc(ch7, fp7b); 303: if(ferror(fp7b)) 304: {printf("error07 305: exit(1);} 306: } 307: if(fclose(fp7a)==-1) 308: {printf("error07 309: exit(1);} 310: if(fclose(fp7b)==-1) 311: {printf("error07 312: exit(1);} 313: if(fclose(fp7temp)==-1) 314: {printf("error07 315: exit(1);} 316: printf(" %s %s ",av[1],av[2]); 317: break; A B case

42 1] 9] 7 A B case 8 char x scanf( ) Yes /No Yes 326 toupper( ) if(toupper(getchar( ))=='Y') Y y 328 remove( ) remove(av[1]) av[1] Yes /No Y case 8 318: /********************* case 8 ***********************/ 319: case 8: 320: char x; 321: if(!(ac==2)) 322: {printf("error08 [ ] < >_< > 323: exit(1);} 324: printf(" ( es Y/No Y ) 325: scanf("%c",&x); 326: if(toupper(getchar())=='y') 327: { 328: remove(av[1]); 329: printf(" %s ",av[1]); 330: } 331: else 332: printf(" 333: break; case

43 1] 9] 8 (Yes Y/No Y ) Y case 9 334: /*************************** case9 ****************************/ 335: case 9: 336: printf(" 337: break; 338: default: 339: printf(" 340: } 341: } 342: return 0; 343: }

44 4 if (ac==1) else (!(ac==1)) 5 (1) (2) (1) (2) Ctrl C ++ Visual C++ Java

45 6 7 [ ] C ( ) Herbert Schildt SE C ( ) Steve Oualline ( )

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

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

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

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

新版明解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

ファイル入出力

ファイル入出力 C プログラミング Ⅱ の基礎 とは ファイルへデータを書き込んだり ( 出力 ), ファイルからデータを読み込んだり ( 入力 ) する C 言語では キーボードからの入力 画面への出力と同じようなコードで 処理を実現できる プログラム 入力 出力 ファイル 出力 入力 2 入出力の基本 ストリーム プログラム上で様々な装置への入出力を行う機構様々な入出力装置を統一的な方法で扱うことができる ハードディスクなどではファイルデータによって入出力が行われる

More information

ファイル入出力

ファイル入出力 C プログラミング Ⅱ の基礎 とは ファイルへデータを書き込んだり ( 出力 ), ファイルからデータを読み込んだり ( 入力 ) する C 言語では キーボードからの入力 画面への出力と同じようなコードで 処理を実現できる プログラム 入力 出力 ファイル 出力 入力 2 入出力の基本 ストリーム プログラム上で様々な装置への入出力を行う機構様々な入出力装置を統一的な方法で扱うことができる ハードディスクなどではファイルデータによって入出力が行われる

More information

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

Microsoft Word - Cプログラミング演習(9) 第 9 回 (6/18) 3. ファイルとその応用 外部記憶装置に記録されたプログラムやデータを, ファイルと呼ぶ シーケンシャルファイルやランダムファイルへのデータの記録や読み出し, 更新の手順について学習する (1) ファイルとレコードファイル複数の関連したデータを一つに集めたり プログラムを外部記憶装置に保存したものレコードファイルを構成する一塊のデータ ex. 個人カードフィールドレコードを構成する個別の要素

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

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

スライド タイトルなし

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

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

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション プログラミング初級 第 13 回 2017 年 7 月 10 日 標準ライブラリ関数 1 標準ライブラリ関数とは 関数には (1) 自分で作る関数 (2) はじめから用意されている関数特に C 言語用用意されているもの : 標準ライブラリ関数 文字列の代入文字列の長さを求める文字列の比較文字列の連結 strcpy strlen strcmp strcat 2 文字列の操作 - 具体例を通して (141

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

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

+ +

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

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

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

: 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

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

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

新・明解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

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

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

: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

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

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (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

超初心者用

超初心者用 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

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

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

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

ディジタル信号処理

ディジタル信号処理 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 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

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

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

USB 0.6 https://duet.doshisha.ac.jp/info/index.jsp 2 ID TA DUET 24:00 DUET XXX -YY.c ( ) XXX -YY.txt() XXX ID 3 YY ID 5 () #define StudentID 231

USB 0.6 https://duet.doshisha.ac.jp/info/index.jsp 2 ID TA DUET 24:00 DUET XXX -YY.c ( ) XXX -YY.txt() XXX ID 3 YY ID 5 () #define StudentID 231 0 0.1 ANSI-C 0.2 web http://www1.doshisha.ac.jp/ kibuki/programming/resume p.html 0.3 2012 1 9/28 0 [ 01] 2 10/5 1 C 2 3 10/12 10 1 2 [ 02] 4 10/19 3 5 10/26 3 [ 03] 6 11/2 3 [ 04] 7 11/9 8 11/16 4 9 11/30

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

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

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

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

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

数値計算

数値計算 数値計算 垣谷公徳 17 号館 3 階電子メール : kimi@ee.ous.ac.jp プログラミング言語の一般論 データ型 ( 定数と変数 配列 ) 代入 基本演算 ( 四則演算 ) 入出力 分岐 繰返処理 関数 外部手続き 1 2 入力関数 入出力 getchar, getc, fgetc ; 一文字入力 gets, fgets, fread ; 文字列 ( データ列 ) 入力 scanf,

More information

データ構造

データ構造 アルゴリズム及び実習 7 馬青 1 表探索 定義表探索とは 表の形で格納されているデータの中から条件に合ったデータを取り出してくる操作である ただし 表は配列などで実現できるので 以降 表 の代わりに直接 配列 などの表現を用いる場合が多い 表探索をただ 探索 と呼ぶ場合が多い 用語レコード : 表の中にある個々のデータをレコード (record) と呼ぶ フィールド : レコードが名前と生年月日などで構成されているとすれば

More information

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

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

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言語によるアルゴリズムとデータ構造 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

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

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

計算機プログラミング

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

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

web07.dvi

web07.dvi 93 7 MATLAB Octave MATLAB Octave MAT MATLAB Octave copyright c 2004 Tatsuya Kitamura / All rights reserved. 94 7 7.1 UNIX Windows pwd Print Working Directory >> pwd ans = /home/kitamura/matlab pwd cd Change

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

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

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

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

slide4.pptx

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

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

ディジタル信号処理

ディジタル信号処理 信号処理論 ディジタル画像処理 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

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

Microsoft Word - 06

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

More information

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

1. ファイルにアクセスするには ファイルにアクセスするには 1. ファイルを開く 2. アクセスする 3. ファイルを閉じるという手順を踏まなければなりません 1.1. ファイルを読み込む まずはファイルの内容を画面に表示させるプログラムを作りましょう 開始 FILE *fp char fname ファイル入出力 三池克明 ファイルのデータを読込む あるいは書込む方法と CSV 形式のファイル処理 について解説します 目次 1. ファイルにアクセスするには... 1 1.1. ファイルを読み込む...1 1.2. ソースコードを簡潔にする...9 1.3. ファイルに書き込む...11 2. CSV ファイルにアクセスする... 14 2.1. CSV ファイルを作成する...14 2.2.

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

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

Microsoft Word - Cプログラミング演習(10) 第 10 回 (6/25) 3. ファイルとその応用 (3) ファイルの更新 シーケンシャルファイルの更新 シーケンシャルファイルでは, 各レコードが可変長で連続して格納されており, その中の特定のレコードを変更することができない そこで一般的には, マスタファイルからデータを取り出し, 更新処理を行ったあとに新マスタファイルに書き込む 注 ) マスタファイル : 主ファイル, 基本ファイルと呼ばれるファイルで内容は比較的固定的であり,

More information

プログラミング基礎

プログラミング基礎 C プログラミング 演習 アルゴリズム基礎論 演習 第 10 回 今後の予定 12/22( 月 ) 期末試験 (60 分間 ) 場所 :A1611 時間 :16:20~17:20 課題の最終提出締切 :12/19( 金 ) これ以降の新規提出は評価されない 12/22までに最終状況を提示するので, 提出したのに や になってる人は自分の提出内容や提出先を再確認した上で12/26までに問い合わせること

More information

1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

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

Microsoft Word - cpro_m_13.doc

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

More information

02: 変数と標準入出力

02: 変数と標準入出力 C プログラミング入門 基幹 7 ( 水 5) 1 10: ファイル入出力 Linux にログインし 以下の講義ページを開いておくこと http://www-it.sci.waseda.ac.jp/teachers/w48369 2/CPR1/ 2016-06-15 今日の内容 2 標準ライブラリ関数によりファイルの出力を行う画像ファイルの生成を例題として 配列の作成を復習する 文字列の扱いを復習する

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

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

kiso2-06.key

kiso2-06.key 座席指定があります Linux を起動して下さい 第6回 計算機基礎実習II 計算機基礎実習II 2018 のウェブページか ら 以下の課題に自力で取り組んで下さい 第5回の復習課題(rev05) 第6回の基本課題(base06) 第5回課題の回答例 ex05-2.c 1. キーボードから整数値 a を入力すると a*a*a の値を出力することを繰り返すプログラムを作成しなさい 2. ただし 入力された

More information

目次

目次 プログラミング I 第数理物理, 総合理学等向け 2018 年 11 月 24 日土 海谷治彦 1 目次 ファイルとは何か? プログラムからファイルを扱うには? ファイルの読み込み ファイルの書き込み ファイルの削除, 名称変更 2 電源を切ってもデータが残ってる! コンピュータの電源を切って再起動しても, データは残っている. ワードの文書,MP3 ファイル, 画像ファイル, プログラムファイル

More information

Microsoft PowerPoint - kougi4.ppt

Microsoft PowerPoint - kougi4.ppt C の実行モデル 自由落下距離 前回の授業の 例題 1 の復習と重要事項 の確認 地上で物を落とし始めた後の自由落下距離を 求める 重力加速度 g は 9.8 とする 自由落下距離を求めるために, プログラム中に, 計算式 y = ( 9.8 / 2.0 ) * x * x を書く C++ ソースファイルの編集 編集画面 編集中のファイル名 関係するファイルなどが表示される ビルド結果などが表示される画面

More information

演算増幅器

演算増幅器 ファイルこれまでにデータの入力方法として キーボードからの入力を用いてきた 構造体を習った際に実感してもらえたと思うが 入力データ量が多いときにはその作業は大変なものとなり 入力するデータを間違えた場合には最初からやり直しになる そこで今回はこれらの問題を解決するため あらかじめ入力データをテキストエディタなどで編集し ファイルとして保存したものを入力データとして用いる方法を習っていく さらにプログラムで作成したデータをファイルに出力する方法も併せて習っていく

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

02: 変数と標準入出力

02: 変数と標準入出力 C プログラミング入門 基幹 7 ( 水 5) 10: ファイル入出力 Linux にログインし 以下の講義ページを開いておくこと http://www-it.sci.waseda.ac.jp/ teachers/w483692/cpr1/ 2016-06-15 1 標準ライブラリ関数によりファイルの出力を行う 画像ファイルの生成を例題として 配列の作成を復習する 今日の内容 関数を作ってプログラムを構造化する

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

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

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² – (2018) 11 2018 12 13 2 g v dv x dt = bv x, dv y dt = g bv y (1) b v 0 θ x(t) = v 0 cos θ ( 1 e bt) (2) b y(t) = 1 ( v 0 sin θ + g ) ( 1 e bt) g b b b t (3) 11 ( ) p14 2 1 y 4 t m y > 0 y < 0 t m1 h = 0001

More information

prog-text.dvi

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

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

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

Java updated

Java 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

数値計算

数値計算 プログラム作成から実行まで 数値計算 垣谷公徳 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

C言語入門

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

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:

[ 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

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

橡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

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

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç 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 information

情報処理演習 B8クラス

情報処理演習 B8クラス 予定スケジュール ( 全 15 回 ) 1 1. 終了 プログラミング言語の基礎 2. 終了 演算と型 3. 終了 プログラムの流れの分岐 (if 文,switch 文など ) 4. 終了 プログラムの流れの繰返し (do, while, for 文など ) 5. 終了 中間レポート1 6. 終了 配列 7. 終了 関数 8. 終了 文字列 ( 文字列の配列, 文字列の操作 ) 9. 終了 ポインタ

More information

Microsoft PowerPoint - C_Programming(3).pptx

Microsoft PowerPoint - C_Programming(3).pptx H23 年度秋学期情報スキル活用 入門 担当 : 田中基彦 ( 工学部共通教育科 ) Email: ak_tanaka@isc.chubu.ac.jp 授業のホームページ学術情報センター > 教育支援 > 情報リテラシー 授業の日程 講義内容提出課題 連絡事項を掲載 > 定期的にアクセスして確認する C 言語によるプログラミング (3) 制御文 繰り返し文 if, while, switch, for,

More information

PowerPoint Presentation

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

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

6 6.1 sound_wav_files flu00.wav.wav 44.1 khz 1/44100 spwave Text with Time spwave t T = N t N 44.1 khz t = 1 sec j t f j {f 0, f 1, f 2,, f N 1

6 6.1 sound_wav_files flu00.wav.wav 44.1 khz 1/44100 spwave Text with Time spwave t T = N t N 44.1 khz t = 1 sec j t f j {f 0, f 1, f 2,, f N 1 6 6.1 sound_wav_files flu00.wav.wav 44.1 khz 1/44100 spwave Text with Time spwave t T = t 44.1 khz t = 1 sec 44100 j t f j {f 0, f 1, f 2,, f 1 6.2 T {f 0, f 1, f 2,, f 1 T ft) f j = fj t) j = 0, 1, 2,,

More information

memo

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

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

第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

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

ゲームエンジンの構成要素 cp-3. 計算 (C プログラムの書き方を, パソコン演習で学ぶシリーズ ) https://www.kkaneko.jp/cc/adp/index.html 金子邦彦 1 本日の内容 例題 1. 自由落下距離四則演算例題 2. 三角形の面積浮動小数の変数, 入力文, 出力文, 代入文例題 3. sin 関数による三角形の面積ライブラリ関数 2 今日の到達目標 プログラムを使って, 自分の思い通りの計算ができるようになる

More information