| | |
Need Help
![]() |
•
•
Join Date: Aug 2004
Posts: 24
Reputation:
Solved Threads: 0
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?
/* 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?
•
•
Join Date: Aug 2004
Posts: 140
Reputation:
Solved Threads: 1
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.
•
•
•
•
Originally Posted by XianBin
main() function is have tow paras like this : argv[], argc
int main(argv[],argc).
C Syntax (Toggle Plain Text)
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.
"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
![]() |
Other Threads in the C Forum
- Previous Thread: "\x00" problem
- Next Thread: A mistake about struct
| Thread Tools | Search this Thread |
* adobe ansi api array arrays bash binarysearch calculate centimeter char cm convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hardware highest homework i/o ide inches initialization intmain() iso km linked linkedlist linux linuxsegmentationfault list logical_drives loopinsideloop. lowest match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation pattern pdf performance pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h






