Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Redirecting Input and Output in C.

  1. Mar 15, 2010 #1

    AK2

    User Avatar

    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.
     
  2. jcsd
  3. Mar 15, 2010 #2
    programm.exe < input.txt > output.txt
    Either enter that in a dosshell or modify the command of your shortcut
     
  4. Mar 15, 2010 #3

    Mark44

    Staff: Mentor

    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.
     
  5. Mar 15, 2010 #4
    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
     
  6. Mar 17, 2010 #5

    AK2

    User Avatar

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Redirecting Input and Output in C.
  1. Taking inputs in C (Replies: 11)

  2. MIPS input/output (Replies: 20)

  3. C - getting input (Replies: 3)

  4. MIPS Input/Output? (Replies: 1)

Loading...