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?

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.

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.

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.

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.

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

This article has been dead for over six months. Start a new discussion instead.