954,141 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need Help

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
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?

Brent_Ritterbec
Newbie Poster
24 posts since Aug 2004
Reputation Points: 12
Solved Threads: 0
 

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.

chound
Junior Poster
145 posts since Aug 2004
Reputation Points: 15
Solved Threads: 1
 

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.

Brent_Ritterbec
Newbie Poster
24 posts since Aug 2004
Reputation Points: 12
Solved Threads: 0
 

Where have you redirected the stream?

chound
Junior Poster
145 posts since Aug 2004
Reputation Points: 15
Solved Threads: 1
 

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.

XianBin
Newbie Poster
24 posts since Aug 2004
Reputation Points: 15
Solved Threads: 0
 
main() function is have tow paras like this : argv[], argc int main(argv[],argc).

ITYM

int main(int argc, char *argv[])
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.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

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

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You