널문자 - 해당되는 글 1건

#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>

main(int argc, char *argv[])
{
    int fd;
    off_t filesize;

    if ((fd = open(argv[1], O_RDONLY)) == -1) {
       perror("open failed");
       exit(1);
    }
   /* 읽기/쓰기 포인터가 파일의 끝을 가리키게 되고,
       변경된 읽기/쓰기 포인터가 반환되는데 이는 파일의 크기가 된다. */
    if ((filesize=lseek(fd, 0, SEEK_END)) == -1) {
       perror("lseek failed");
       exit(1);
    }
    printf("%s\'s size is %d\n", argv[1], filesize);
    close(fd);
    exit(0);
}
===============================
5555.txt 파일이 생성되었고
그파일의 용량은 34바이트이다 26개쓴상태에서 4만큼 널집어넣고 4바이트인 ABCD를 써버려서
--------------------------------

      c 언어  |  2007. 9. 13. 12:29



sokoban's Blog is powered by Daum & Tattertools