I've seen this question has been asked before, but none of the answers seemed to work for my problem.
I am attempting to write a function that will read the contents of a file, and print them. Here is my code;
int main()
{
int c;
fseek(stdin, 0, SEEK_SET);
c = getc(stdin);
while ((c = getchar()) != EOF)
{
putchar(c);
fseek(stdin, 1, SEEK_CUR);
c = getc(stdin);
}
}
When running the code, I pipe in a file using;
./[Program] < [File.txt]
eg.
./FileRead < Hello.txt
However, when I run it, I get a jumble of random letters. Here is an example:
The contents of the file I am piping in:
Hello World!
This is a test file.
I hope this works!
And here is the output:
eood
Tss sfe
Io iwk
Can anyone help me work out what is wrong?