I'm making a program to be opened this way:
How can i read the in.file using the stdin parameter?$ proj1 <in.file> out.file
How can i get the out.file name to create that output file?
Thanks!
I'm making a program to be opened this way:
How can i read the in.file using the stdin parameter?$ proj1 <in.file> out.file
How can i get the out.file name to create that output file?
Thanks!
You don't need to do anything at all.
fgets( buff, sizeof buff, stdin );
will read a line from the file.
printf( "hello world\n" );
would write to the output file.
Redirections are handled by the shell, not your program.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
just do it...
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
So? As I said - just use it. No difference from the fgets approach Salem suggested... Instead of reading lines - read char by charbut its for college, my teacher says that i need to use getc(stdin) to receive the file, i know that are other ways but that is a must unfortunatly
Code:int c; while((c=getc(stdin)) != EOF) { process char here }
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
ok thanks!!