1 / 9

리눅스 시스템 프로그래밍 (ex2-5)

리눅스 시스템 프로그래밍 (ex2-5). 2007242039 김창현. 예제 2-5. 텍스트 파일을 읽어들여 lookup 테이블을 생성하여 숫자를 입력 받으면 해당 숫자에 해당하는 라인을 출력한다 . 라인번호가 0 보다 작으면 프로그램 종료 . Lookup 테이블 구조 static struct { long offset ; /* 파일 내의 라인 offset 을 저장한다 */ int len ; /* 라인의 길이를 저장한다 */ } table [TABSIZE] ;.

monita
Download Presentation

리눅스 시스템 프로그래밍 (ex2-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. 리눅스 시스템 프로그래밍(ex2-5) 2007242039 김창현

  2. 예제 2-5 • 텍스트 파일을 읽어들여lookup 테이블을 생성하여 숫자를 입력 받으면 해당 숫자에 해당하는 라인을 출력한다. • 라인번호가 0보다 작으면 프로그램 종료. • Lookup 테이블 구조 • static struct { long offset ; /* 파일 내의 라인 offset을 저장한다 */ intlen ; /* 라인의 길이를 저장한다 */ } table [TABSIZE] ;

  3. ex2-2 Code 2 1

  4. ex2-2 소스설명 (1) table [0] table table table table [99] [3] [2] [1] intlen long offset intlen intlen intlen intlen long offset long offset long offset long offset 100개 char buf 512개

  5. ex2-2 소스설명 (2) \n 을 만나면 offset 증가 EX) 읽을 문서 = test.txt AAA BBBB CCCCC While & for table table table [2] [0] [1] AAA \n BBBB \n CCCCC Len 4 Len 5 Len 6 Offset 4 Offset 9 Offset 0 1 글자마다 len증가 완성된 lookup Table

  6. ex2-2 Code

  7. ex2-2 소스설명 (3) table table table [1] [2] [0] Len 5 Len 4 Len 6 Offset 9 Offset 4 Offset 0 읽을 위치 설정 AAA \n BBBB \n CCCCC lseek 완성된 lookup Table 설정된 위치부터 길이만큼 읽어서 buf에 넣음 read char buf

  8. 실행화면

  9. 실행화면 (/etc/group)

More Related