Contents

조회 수 7152 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
885 Develop [c] 단기과정[01/07] 제어문, 피보나치수열 hooni 2003.04.23 7410
884 Develop [c] 단기과정[01/08] (다차원 + 배열)포인터, void 포인터 hooni 2003.04.23 7770
883 Develop [c] 단기과정[01/08] 과제.. 파스칼 삼각형 file hooni 2003.04.23 7256
882 Develop [c] 단기과정[01/08] 배열, 포인터 hooni 2003.04.23 7223
881 Develop [c] 단기과정[01/10] 과제.. swap(any data, ..) file hooni 2003.04.23 6904
880 Develop [c] 단기과정[01/14] 파일 입출력 file hooni 2003.04.23 6821
879 Develop [c] 단기과정[01/14] 피보나치, 파스칼.. 파일입출력 file hooni 2003.04.23 7081
878 Develop [c] 단기과정[01/15] 피보나치, 파스칼.. 링크리스트 file hooni 2003.04.23 7234
877 Develop [c] 단기과정[01/17] 후위연산 스택 계산기.. file hooni 2003.04.23 7226
876 Develop [c] 단기과정[01/24] 정렬 알고리즘 hooni 2003.04.23 6955
875 Develop [c] 단어 입력/수정 프로그램 소스 file hooni 2003.04.23 7028
874 Develop [c] 달팽이 배열? 인지 먼지.. ㅋㅋ hooni 2013.04.23 7130
Board Pagination Prev 1 ... 20 21 22 23 24 25 26 27 28 29 ... 98 Next
/ 98