Redirecting Input and Output in C.

  • Thread starter Thread starter AK2
  • Start date Start date
  • Tags Tags
    Input Output
AI Thread Summary
Redirecting both input and output in a Windows operating system can be achieved through file I/O in C programming. To redirect output, open a file with fopen, use fprintf or similar functions to write to it, and close the file with fclose. For input, utilize fscanf or other file input functions. Additionally, functions like sscanf and sprintf can facilitate input and output to strings, which can be particularly useful when managing carriage return characters. Understanding C streams is also beneficial for programming microcontrollers and other engineering applications, enhancing overall programming skills in these areas.
AK2
Messages
39
Reaction score
0
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.
 
Technology news on Phys.org
programm.exe < input.txt > output.txt
Either enter that in a dosshell or modify the command of your shortcut
 
AK2 said:
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.
 
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
 
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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top