문제

Like in the topic, I'd like to read from standard input and print to standard output whole file with no difference between them.

program < data.txt > data.out
diff data.txt data.out // <- the same

File contains Unicode letters.

I've managed write following piece of code:

char s[100000];

int main()
{
    setmode(1, _O_BINARY);

    char *n;

    do {
        n = gets(s);
        s[strlen(s)-1] = '\n';
        printf("%s", s);
    }
    while(n);

    return 0;
}

but input and output is slighty different (input: 76 465KB, output: 76 498KB)

Thanks in advance.

EDIT:

Now, it's only 2KB difference.

EDIT:

It's OK.

도움이 되었습니까?

해결책

It could happen if the input file has \n line endings. The output file will have \r\n line endings on Windows. That could explain the difference.

If you don't want to output the \rs, you can follow this answer

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top