UNIX C
ls mkdir man http://www.tj.chiba-u.jp/lecture/prog2/
Ctrl+x, Ctrl+s ( )..[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 Wall o hoge hoge.c..[7]%!../hoge 1 :!g g!!!..!ls!gcc
cp : cp. cp hoge.c hoge2.c hoge.c hoge2.c cp hoge.c jikken1/hoge3.c hoge.c jikken1 hoge3.c mv : ( ) mv. mv hoge.c jikken1/hoge2.c hoge.c jikken1 hoge2.c hoge.c cat : cat cat more. cat hoge.c more hoge.c Return (Enter) 1 q
( ) ( ) C
C ( ) Q1 A1 fopen Q2 A2 Q3 A3 Q4 A4 fclose
#include <stdio.h> #include <stdlib.h> int main(void) { int i, dat, sum = 0; FILE *fp /* exit if ( ( fp = fopen( indata.dat, r ) ) == NULL ) { } /* printf( n ); exit(1); for (i = 1 ; ; i++){ fscanf(fp, %d, &dat); /* if(dat == 0) /* 0 break; sum += dat; /* } printf( %d n, sum); /* } fclose(fp); return(0); /*
FILE *fp if ( ( fp = fopen( indata.dat, r ) ) == NULL ); /* { printf( n ); exit(1); } FILE *fp; C FILE FILE FILE stdio.h stdio.h
FILE *fp; a b /* fp FILE *fp; c d e
FILE *fp if ( ( fp = fopen( indata.dat, r ) ) == NULL ); /* { printf( n ); exit(1); } fp = fopen(, )
ab wb rb a r w b UNIX Windows C html C
fp = fopen(, ); a /* b fp = fopen( b, r ) ; b b c b d e
fp 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 k o n o m o j i r e t s u n o n a r a b i n i h a i m i h a a r i m a s e n 2 1
fclose(fp); /* fclose (fp);
fclose( fp ) ; a b /* b fp fclose(fp) ; d b c e
b d FILE *fp1; FILE *fp2; fp1 = fopen( b, r ); fp2 = fopen( d, w ); fclose( fp2 ); fclose( fp1 ); fp1 b a d fp2 d c b e
FILE *fp if ( ( fp = fopen(, ) ) == NULL ); /* { printf( n ); exit(1); } fclose (fp) /*
fgetc / fputc fgets / fputs fscanf / fprintf fread / fwrite
fgetc / fputc getchar putchar c = fgetc(fp); 8 EOF ( End of File ) c int fputc(c, fp)
C 1 a a b c d e f g h i j k l m n o p q r s b 2 c 3 4 EOF unsigned char int fgetc
mule rsample.txt cat #include <stdio.h> #include <stdlib.h> int main(void) { FILE *fpr; FILE *fpw; int c; /* if ( ( fpr = fopen( rsample.txt, r ) ) == NULL ) { return(0); printf( n ); } exit(1); } /* if ( ( fpw = fopen( wsample.txt, w ) ) == NULL ) { printf( n ); exit(1); } /* while (( c = fgetc(fpr) )!= EOF) { fputc( c, fpw ); } /* fclose(fpw); /* fclose(fpr);
fgets / fputs gets puts fgets( buf,,fp); NULL buf char fputs(buf, fp)
buf 1 a b c d e n 0 null null 2 f g h i j k l m n n 3 o p q r s t 0 0 a b c d e f g h i j k l m n o p q r s t null
#include <stdio.h> #include <stdlib.h> #define MAX_STRINGS 50 int main(void) { FILE *fpr; FILE *fpw; int c; char data[max_strings]; return(0); /* } if ( ( fpr = fopen( rsample.txt, r ) ) == NULL ) { printf( n ); exit(1); } /* if ( ( fpw = fopen( wsample.txt, w ) ) == NULL ) { printf( n ); exit(1); } /* while ( fgets( data, MAX_STRINGS, fpr )!= NULL) { fputs( data, fpw ); } /* fclose(fpw); /* fclose(fpr);
fscanf / fprintf scanf printf fscanf (fp,, ); fprintf (fp,, ); scanf / printf
indata.dat indata.dat mule cat indata.dat ( : ) http://www.cfme.chiba-u.jp/~yama/j1/indata.dat
#include <stdio.h> #include <stdlib.h> int main(void) { int i, dat, sum = 0; FILE *fp; /* exit if ( ( fp = fopen( indata.dat, r ) ) == NULL ) /* { printf( n ); exit(1); } for (i = 1 ; ; i++){ fscanf(fp, %d, &dat); /* if(dat == 0) /* 0 break; sum += dat; /* } printf( %d n, sum); /* fclose(fp); /* } return(0);