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;
}


?

  1. [c++] mfc에서 윈도우 항상 위 속성 주기..

  2. [c++] Win32 API 기본 출력인 MessageBox() 함수 사용 예제..

  3. [c] 파이프(popen)로 다른 프로세스 실행결과 가져오기

  4. [c] 도메인(호스트)으로 IP정보 알아오기.. (nslookup과 비슷)

  5. [c] UTF-8을 EUC-KR로 변환.. (iconv)

  6. [c] 바로 보고 정리할 것.. ㅋㄷㅋㄷ

  7. [c] openssl 샘플코드.. 어려움 ㅠㅠ

  8. [linux] 한글 URL 인식할 수 있게 아파치(Apache) 설정 (mod_url.c 설치)

  9. [c] 가변인자 함수(printf와 같은..)

  10. [c#] BHO 한샘툴바랑 동현툴바..

  11. [c++] Win32API를 이용한 ExitWindowsEx 사용한 예제코드

  12. [c#] mfc 기반의 웹서비스 서버/클라이언트 샘플과 예제 소스

Board Pagination Prev 1 ... 48 49 50 51 52 53 54 55 56 57 ... 98 Next
/ 98