Redirecting Input and Output in C.

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

Discussion Overview

The discussion revolves around redirecting input and output in the C programming language, specifically within the context of the Windows operating system. Participants explore methods for handling standard input and output, as well as file I/O operations.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant inquires about redirecting both input and output in Windows, noting that their reference material only covers DOS.
  • Another participant suggests using the command programm.exe < input.txt > output.txt in a command shell or modifying a shortcut command.
  • A different participant clarifies that redirecting I/O in a C program involves using file I/O functions like fopen, fprintf, and fclose for output, and fscanf for input.
  • Another contribution mentions the use of sscanf and sprintf for input and output to strings, highlighting their utility in managing carriage return characters with fgets.
  • A participant expresses gratitude for the responses and poses a follow-up question about the relevance of learning C streams for programming PIC microcontrollers and other engineering applications.

Areas of Agreement / Disagreement

Participants have shared various methods and insights regarding input and output redirection in C, but there is no consensus on the best approach or the implications for programming microcontrollers.

Contextual Notes

The discussion includes various methods for handling input and output in C, but does not resolve the effectiveness or applicability of these methods in specific engineering contexts, such as microcontroller programming.

Who May Find This Useful

Individuals interested in C programming, particularly in the context of input/output operations and applications in engineering or embedded systems.

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