Redirecting Input and Output in C.

  • Thread starter Thread starter AK2
  • Start date Start date
  • Tags Tags
    Input Output
Click For Summary
SUMMARY

This discussion focuses on redirecting input and output in C programming on Windows operating systems. Users can utilize file I/O functions such as fopen, fprintf, and fclose for output, while fscanf serves for input redirection. The conversation also highlights the utility of C streams for programming applications like PIC microcontrollers. Overall, understanding these functions is essential for effective I/O management in C.

PREREQUISITES
  • Basic understanding of C programming language
  • Familiarity with file I/O functions in C
  • Knowledge of standard input and output streams
  • Experience with Windows command line operations
NEXT STEPS
  • Explore fopen and fclose for file handling in C
  • Learn about fscanf and fprintf for formatted input and output
  • Investigate C streams and their applications in embedded systems
  • Study command line redirection techniques in Windows
USEFUL FOR

Programmers working with C, embedded systems engineers, and anyone interested in mastering input/output operations in software development.

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.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
Replies
1
Views
2K
Replies
3
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
Replies
12
Views
3K