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
번호 분류 제목 글쓴이 날짜 조회 수
405 Develop [php] 정규표현식 간단히 정리 hooni 2013.04.23 6459
404 System/OS [linux] 콘솔 기본언어 설정 방법 hooni 2013.04.23 12834
403 Develop [js] selectbox 선택 후 input 박스에 적용 hooni 2013.04.23 8335
402 Develop [ajax] 이벤트 코드 생성기 작업중.. ㅋㅋ file hooni 2013.04.23 7124
401 System/OS [sql] 중복데이터 삭제 쿼리 hooni 2013.04.23 14739
400 System/OS [sql] 조회구문(select)에서 중복 데이터를 한 번만 출력 (distinct) 1 hooni 2013.04.23 33947
399 Develop [php] 날짜 정보 출력 (년,월,일,시,분,초) hooni 2013.04.23 10534
398 Develop [c] KNN(K-nearest neighbor) 패턴인식 과제.. file hooni 2013.04.23 7396
397 Develop [c] 베이지언(Bayesian) 패턴인식 과제 ㅋㅋ file hooni 2013.04.23 7101
396 Develop [js] php의 number_format() 함수와 같은.. ㅋㅋ hooni 2013.04.23 6939
395 Develop [c] 숫자 맞추는 게임.. file hooni 2013.04.23 6936
394 Develop [c] 구조체 배열 예제 (학생 성적 계산) file hooni 2013.04.23 7671
Board Pagination Prev 1 ... 60 61 62 63 64 65 66 67 68 69 ... 98 Next
/ 98