| | |
Need Help
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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
Views: 2242 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C
#include * .net append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






