Contents

조회 수 7158 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
#define MAXSIZE 65535
#define CRLF "\n"

#include <string.h>
#include <stdio.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

const char *getline(int sockfd){
        static char buf[MAXSIZE + 1] = "";
        static char *pbuf = buf;

        int i;
        ssize_t len;

        char *retptr;
        char *crlf;

        do{
                /* 개행문자 찾으면 */
                if(crlf = strstr(pbuf, CRLF)){
                        retptr = pbuf;

                        pbuf = crlf + strlen(CRLF);
                        *crlf = '\0';

                        return retptr;
                }
                
                /* 못 찾았으면 */
                len = strlen(pbuf);
                for(i = 0; i < len; i++) buf[i] = pbuf[i];
                pbuf = buf;
        }while(read(sockfd, buf + len, MAXSIZE - len) > 0);
        /* 데이터 읽고 다시 개행문자 있는지 검사하러 올라가자 */

        return NULL; // 에러 또는 EOF
}

int main(){
        const char *line;

        int fd;
        fd = open("test.c", O_RDONLY);

        while(line = getline(fd))
                printf("LINE : '%s'\n", line);

        close(fd);

        return 0;
}


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
361 Develop [java] 채팅 프로그램.. swing 사용.. file hooni 2013.04.23 8360
360 Develop [c] 구조체의 설명과 예제.. hooni 2003.04.23 8388
359 Develop 다양한 방법으로 아주 큰 수(Big Number) 계산.. ㅋㅋ hooni 2013.04.23 8390
358 Develop [c] 패킷 유량/프로토콜 통계 모니터링.. file hooni 2013.04.23 8391
357 Develop [js] 자바스크립트로 만든 게임 file hooni 2013.04.23 8400
356 Develop [c] 파이프(popen)로 다른 프로세스 실행결과 가져오기 file hooni 2013.04.23 8403
355 Develop [c] CGI Library to C^^ hooni 2003.04.23 8432
354 Develop [c] 쓰레드에 대한 내용 퍼오기..ㅡㅡ; hooni 2013.04.23 8442
353 Develop [c][cpp] mfc, win32api, 예제 소스 대박 모음~ file hooni 2013.04.23 8473
352 Develop [java] 메모패드.. 스윙(swing)으로.. file hooni 2013.04.23 8478
351 Develop [php] 그래프 그리는 프로그램.. file hooni 2013.04.23 8478
350 Develop [c] 소수점 반올림^^ hooni 2003.04.23 8491
Board Pagination Prev 1 ... 36 37 38 39 40 41 42 43 44 45 ... 71 Next
/ 71