...

View Full Version : c accept redirect file



DELOCH
10-13-2012, 11:06 PM
I am making a test program that is redirected a text file and the program
is required to store and display the redirected input in an string.

sample run:

given mytextfile.txt:
T
TE
TES
TEST
TES
TE
T

run:
mycprogram < mytextfile.txt

output:
T
TE
TES
TEST
TES
TE
T

..

I've been trying to treat the redirect as a stdin input, so something like:


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

main() {
char rinput[200];

fscanf(stdin, "%s", rinput);
fprintf(stdout, "%s\n", rinput);
}


however, this program displays three arbitrary characters on run, instead
of the expected output.

Any help is appreciated.
Thanks ahead of time.
DELOCH

DELOCH
10-20-2012, 10:07 PM
Let me rephrase the problem.

The program works under ssh, and linux, but doesn't give desirable output
in MINGW.

Is there a way to redirect a file to program in MinGW?
Eg:
filea.txt:
A B
C D

program.c:
something

run:
./program < filea.txt
output: A, B, C, D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum