프로그래밍

 3198, 1/160 회원가입  로그인  
   zeros47
   유닉스 파일 분할 코드 질문입니다.

http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=3100 [복사]


#include <stdio.h>
#include <stdlib.h>

int main(int argc,char *argv[])
{
    FILE *ifp, *ofp;
    char outfile[50], *buf;
    int rdCnt, fileCnt = 0;

    if (argc != 2) exit(-99);

    if (!(ifp = fopen("normal.txt","rb")) ) {
        printf("Open error\n");
        return 0;
    }
    buf = (char*)malloc( atoi(argv[0]) );

    while( (rdCnt = fread(buf,1,1000,ifp))>0 ) {
        sprintf(outfile,"TEST_%d.txt",fileCnt++); // outfile name: TEST_0.txt, TEST_1.txt
        ofp = fopen(outfile,"wb");
        fwrite(buf,1,rdCnt,ofp);
        fclose(ofp);
    }
    fclose(ifp);
}

이런식으로 코드를 짠다음 ./split <입력 문자열> 1000 하면 파일을 1000byte단위로 쪼개고 싶은데요.



쪼개지지가 않네요.



그리고 쪼갤 사이즈도 입력받으려면 어떻게 구현해야 될까요?



열심히 해보고 있는데 잘 모르겟네요 조언 부탁드려요~

  Hit : 4987     Date : 2011/07/25 01:45



    
intmain1202 쪼갤 싸이즈를 입력받으시려면

./split <입력문자열> <쪼갤 싸이즈> 하시면되겟네여

그리고 argv[1] 에 문자열이 있구요 그럼 그걸 정수형으로 바꿔주시면 되겟죠~~
2011/07/26  
zeros47 답변 감사드려요~ 2011/08/03