1 / 5

예제 Ex 2-5

예제 Ex 2-5. 2000242009 김도영. #include <fcntl.h> #define TABSIZE 100 #define BUFSIZE 512 main(argc,argv) int argc; char *argv[]; { int n, i, entry, len; int fd, open(); long offset; static struct { long offset; int len;

amalia
Download Presentation

예제 Ex 2-5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 예제 Ex 2-5 2000242009 김도영

  2. #include <fcntl.h> #define TABSIZE 100 #define BUFSIZE 512 main(argc,argv) int argc; char *argv[]; { int n, i, entry, len; int fd, open(); long offset; static struct { long offset; int len; } table[TABSIZE]; char buf[BUFSIZE];

  3. entry = 0; offset = 0; while((n = read(fd, buf, BUFSIZE)) > 0) { for(i=0; i < n; i++) { table[entry].len++; offset++; if(buf[i] == '\n') table[++entry].offset = offset; abcde’\n’ fgh’\n’ wxyz’\n’ long형 변수 table 구조체

  4. for(;;) { printf("Enter line number: "); scanf("%d",&n); if(--n < 0) break; lseek(fd, table[n].offset, 0); if(read(fd, buf, table[n].len) <= 0) continue; buf[table[n].len] = '\0'; printf("%s", buf); } close(fd); exit(0);

More Related