90 likes | 232 Views
Computer Programming in C Chapter 7. 2013 년 가을학기 부산대학교 정보컴퓨터공학부. 7 장 . Input/Output and Built-in Functions. 목차 Standard I/O Formatted I/O File Access Variable Length Argument List Low Level I/O Memory Management . 1. I/O 의 기본 개념 . Standard I/O Standard Input: Input from Keyboard
E N D
Computer Programming in C Chapter 7 2013년 가을학기 부산대학교 정보컴퓨터공학부
7장. Input/Output and Built-in Functions • 목차 • Standard I/O • Formatted I/O • File Access • Variable Length Argument List • Low Level I/O • Memory Management Computer Programming Chapter 7
1. I/O의 기본 개념 • Standard I/O • Standard Input: Input from Keyboard • Standard Output: Output to Screen • #include <stdio.h> • Example while((c=getchar()) != EOF) putchar(c); printf(“No Error\n”); scanf(“%d %d %s”, &year, &number, name); Computer Programming Chapter 7
2. Formatted I/O • Formatted Input, Output: scanf, printf Computer Programming Chapter 7
3. File Access • File Access • Sequential File vs. Random Access File • Some functions for Random Access File • Type: FILE (e.g. FILE *fp) • Functions • fopen, fclose • fgetc, fputc, fprintf, fscanf, fgets, fputs… • fseek: int fseek(fp, offset, origin) • SEEK_SET, SEEK_CUR, SEEK_END • ftell(fp) • rewind(fp) Computer Programming Chapter 7
4. Various Argument List • Number of Arguments: Not Fixed • Example: printf, scanf void minprintf(char *fmt,...) { va_list ap: int ival; double dval; va_start(ap,fmt); /* set ap to the first argument */ ival=va_arg(ap, int); /* fetch next integer argument */ dval=va_arg(ap, double); /* fetch next double argument */ va_end(ap); } Computer Programming Chapter 7
5. Low Level I/O • Low Level I/O • More efficient I/O • Type • int fd; file descriptor maintained by OS • fd=open(fileName,O_RDWR, 0);close(fd) • nbytes=read(fd, buffer, length); • nbytes=write(fd, buffer, length); • lseek: same as fseek except parameters lseek(fd, offset, origin) Computer Programming Chapter 7
6. Memory Managment • malloc(size), calloc(number, size) • Dynamic Allocation vs. Static Allocation Computer Programming Chapter 7