943,355 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2494
  • C RSS
Sep 3rd, 2004
0

Need Help

Expand Post »
I wrote a program that allows me to send data to a file if I wanted to do that by redirecting the data stream. The only problem is that I can't figure out how to make that work from the DOS prompt. Here is the program:

/* echo_eof.c -- repeats input to end of file */
#include <stdio.h>
int main(void)
{
int ch;

while((ch = getchar()) != EOF)
putchar(ch);
return 0;
}

Now say I wanted to redirect to a file called mywords.
The book I have gives this at the DOS prompt:
echo_eof < mywords
but I keep getting an error. Can anyone help me?
Reputation Points: 12
Solved Threads: 0
Newbie Poster
Brent_Ritterbec is offline Offline
24 posts
since Aug 2004
Sep 4th, 2004
0

Re: Need Help

You hae not opened any file at all!!! What does the line " while((ch = getchar()) != EOF)" mean? You have not opened a file so how can you use EOF(End Of File)? Where are you putting the characters in a file? THe putchar function will print the char into the monitor only. Moreover you have to remove the void in main function if you want to give params at the comd prompt.
Reputation Points: 15
Solved Threads: 1
Junior Poster
chound is offline Offline
143 posts
since Aug 2004
Sep 4th, 2004
0

Re: Need Help

Not true. This uses the stdin stream, which if you go to the DOS-Prompt and use the redirection offered by DOS, then you can stream data to a simple text file using this program.
Reputation Points: 12
Solved Threads: 0
Newbie Poster
Brent_Ritterbec is offline Offline
24 posts
since Aug 2004
Sep 4th, 2004
0

Re: Need Help

Where have you redirected the stream?
Reputation Points: 15
Solved Threads: 1
Junior Poster
chound is offline Offline
143 posts
since Aug 2004
Sep 5th, 2004
0

Re: Need Help

main() function is have tow paras like this : argv[], argc
int main(argv[],argc).

you can confirm if user input "<" character in DOS prompt.while argv[] was contain a "<" char , you can create a file and save input strings in it.
Reputation Points: 15
Solved Threads: 0
Newbie Poster
XianBin is offline Offline
24 posts
since Aug 2004
Sep 5th, 2004
0

Re: Need Help

Quote originally posted by XianBin ...
main() function is have tow paras like this : argv[], argc
int main(argv[],argc).
ITYM
  1. int main(int argc, char *argv[])
Quote originally posted by XianBin ...
you can confirm if user input "<" character in DOS prompt.while argv[] was contain a "<" char , you can create a file and save input strings in it.
Redirection will not pass the redirection operator.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Sep 5th, 2004
0

Re: Need Help

What is the error you are getting?

You should be able to read in mywords with '<'; did you mean to write mywords? Then you'd use '>':

echo_eof > mywords
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: "\x00" problem
Next Thread in C Forum Timeline: A mistake about struct





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC