Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-13-2012, 11:06 PM   PM User | #1
DELOCH
Regular Coder

 
DELOCH's Avatar
 
Join Date: Apr 2006
Location: Canada
Posts: 537
Thanks: 4
Thanked 2 Times in 2 Posts
DELOCH is an unknown quantity at this point
c accept redirect file

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:
PHP Code:
#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 is offline   Reply With Quote
Old 10-20-2012, 10:07 PM   PM User | #2
DELOCH
Regular Coder

 
DELOCH's Avatar
 
Join Date: Apr 2006
Location: Canada
Posts: 537
Thanks: 4
Thanked 2 Times in 2 Posts
DELOCH is an unknown quantity at this point
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
DELOCH is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:58 PM.


Advertisement
Log in to turn off these ads.