2009-05-28から1日間の記事一覧

openとread

#include <stdio.h> #include <fcntl.h> int main(){ int fp; char c[20]; fp = open("./test.txt", O_RDONLY); read(fp, c, 20); printf("%s", c); return 0; } /* test.txtは以下 0123456789 0123456789 ちなみに2行目の8まで表示される。*/ C言語の目次</fcntl.h></stdio.h>

fgetcとfputc

#include <stdio.h> int main(){ FILE *fp; char c; fp = fopen("test.txt", "r"); while( (c = fgetc(fp)) != EOF){ /*printf("%c", c);*/ fputc(c, stdout); } fclose(fp); return 0; } C言語の目次</stdio.h>

fgetsとfputs

備忘録、と。 #include <stdio.h> int main(){ FILE *fp; char str[256]; fp = fopen("./test.txt", "r"); while(fgets(str, 256, fp) != NULL){ /* printf("%s", str); */ fputs(str, stdout); } return 0; } C言語の目次</stdio.h>