Redirecting Input and Output in C.

  • Thread starter AK2
  • Start date
  • #1
AK2
39
0

Main Question or Discussion Point

Is there a way you can redirect both input and output in a Windows operating system. The book I am using only explains how to do this in DOS. Thanks.
 

Answers and Replies

  • #2
32
0
programm.exe < input.txt > output.txt
Either enter that in a dosshell or modify the command of your shortcut
 
  • #3
33,179
4,859
Is there a way you can redirect both input and output in a Windows operating system. The book I am using only explains how to do this in DOS. Thanks.
From the title of this thread, it seems that you want to redirect I/O inside a program written in C. To have input come from somewhere other that stdin (the standard input device) or go to somewhere other than stdout (the standard output device), look at file I/O in C.

The basic idea for output is to open a file using fopen, write to it with fprintf or another file output function, and then close the file using fclose.

For input you'll want to use fscanf or another file input function.
 
  • #4
12
0
You can also input or output to a string using sscanf and sprintf. Very helpful when you use fgets and you don't want the carriage return character, imo
 
  • #5
AK2
39
0
Thanks for the responses. I will try out what you posted. I want to ask another question. will learning how to use C streams be useful for programming a pic microcontroller and other engineering applications.
 

Related Threads for: Redirecting Input and Output in C.

Replies
2
Views
1K
  • Last Post
Replies
20
Views
28K
  • Last Post
Replies
1
Views
5K
Replies
4
Views
3K
Replies
6
Views
1K
Replies
5
Views
720
Replies
5
Views
866
Top