Views 7152 Votes 0 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
#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
No. Category Subject Author Date Views
741 Develop [c] 플러드 필링 (flood filling) 알고리즘.. file hooni 2013.04.23 7319
740 Develop [c] 베지어 곡선(Bézier curve) 알고리즘 file hooni 2013.04.23 8557
739 Develop [doc] Equation Solving에 대한 발표자료.. file hooni 2013.04.23 7979
738 Develop [java] 그래픽(도형,다각형..) 이동,확대,축소,회전에 대한 내용.. 1 file hooni 2013.04.23 8636
737 Develop [c][java] 그래픽(graphic)관련 자료와 샘플코드.. file hooni 2013.04.23 9205
736 Develop [php] 피코맥스용 검색엔진 ㅋㅋ file hooni 2013.04.23 6781
735 Develop [js] 자바스크립트 escape()를 PHP로 받기 hooni 2013.04.23 5990
734 System/OS 나중에 해봐야지.. libconv 설치.. ㅡ,.ㅡ; hooni 2013.04.23 19284
733 Develop [js] 한글문서로 된 259가지 자바스크립트 예제파일 file hooni 2013.04.23 6764
732 Develop [c] 코드 최적화에 대해.. hooni 2013.04.23 7655
731 Develop [c] 로또(Lotto) 번호 생성기 file hooni 2013.04.23 7174
730 Develop [c] 그래픽 차트 라이브러리.. 나중에 확인 해볼 거.. file hooni 2013.04.23 8225
729 Develop [c] GD라이브러리 설치 테스트 소스 file hooni 2013.04.23 8143
728 Develop [c] 문자열 치환해주는 str_replace() 함수 file hooni 2013.04.23 7385
727 Develop [c] 숫자(int, Number)를 hex코드로 변환하는 소스 file hooni 2013.04.23 8121
726 Develop [c] 내가 만든 암호화 프로그램.. 좋아^^ file hooni 2013.04.23 7021
Board Pagination Prev 1 ... 26 27 28 29 30 ... 74 Next
/ 74