Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top