Solved

reading/writing to a file using getchar/putchar

Posted on 1997-11-29
7
496 Views
Last Modified: 2010-08-05
How would I copy a file using getchar and putchar?  I have to use those function calls.  As far as I can tell, those functions read and write from/to stdin and stdout.  The only way I have figured so far, is to use freopen to open the files.  However, I need to write to the screen after I have finished copying the file.  If I were to use freopen, how can I tell it to stop using the file as stdout?  Or, if you could suggest a way other than freopen, what would that be? I can not use function calls like fgetc or fputc.  I have to use getchar and putchar.
0
Comment
Question by:cokeman_
7 Comments
 
LVL 5

Expert Comment

by:julio011597
ID: 1256448
Are you not allowed to go with fgetc() and fputc()?
0
 

Author Comment

by:cokeman_
ID: 1256449
Edited text of question
0
 
LVL 84

Expert Comment

by:ozo
ID: 1256450
Then can you dup(STDOUT_FILENO) before you freopen?
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 5

Expert Comment

by:julio011597
ID: 1256451
It is anyway a mess, since freopen() gives back a FILE *.
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1256452
Maybe, if you tell what is this for, we can give some meaningful advice (well, at least, i need it).
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 200 total points
ID: 1256453
Well, if you must use getchar and putchar, then the only thing you can change is what stdin and stdout is pointing to. In this case, you will need to use redirect stdin and stdout using the command line shell:

  myprog <inputfile >outputfile

This will cause your program (myprog) to be executed with the stdin of inputfile and stdout with outputfile.

0
 
LVL 84

Expert Comment

by:ozo
ID: 1256454
That's certainly the easiest way, but if you don't have that option,
you can still do in your program the same thing that the shell does
when it redirects your stdin and stdout.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now