Need Help

Reply

Join Date: Aug 2004
Posts: 24
Reputation: Brent_Ritterbec is an unknown quantity at this point 
Solved Threads: 0
Brent_Ritterbec Brent_Ritterbec is offline Offline
Newbie Poster

Need Help

 
0
  #1
Sep 3rd, 2004
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 140
Reputation: chound is an unknown quantity at this point 
Solved Threads: 1
chound chound is offline Offline
Junior Poster

Re: Need Help

 
0
  #2
Sep 4th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 24
Reputation: Brent_Ritterbec is an unknown quantity at this point 
Solved Threads: 0
Brent_Ritterbec Brent_Ritterbec is offline Offline
Newbie Poster

Re: Need Help

 
0
  #3
Sep 4th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 140
Reputation: chound is an unknown quantity at this point 
Solved Threads: 1
chound chound is offline Offline
Junior Poster

Re: Need Help

 
0
  #4
Sep 4th, 2004
Where have you redirected the stream?
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 24
Reputation: XianBin is an unknown quantity at this point 
Solved Threads: 0
XianBin XianBin is offline Offline
Newbie Poster

Re: Need Help

 
0
  #5
Sep 5th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,361
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 241
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need Help

 
0
  #6
Sep 5th, 2004
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[])
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: Need Help

 
0
  #7
Sep 5th, 2004
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC