LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-13-2010, 02:19 PM   #16
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197

Quote:
Originally Posted by svicino View Post
you guys are probly getting sick of these quesitons.
Maybe not sick of the questions but definitely sick of
Quote:
Code:
int main(char *fileName)
Maybe you want to try again without repeating that mistake.

I didn't look at the rest of your code.
 
Old 05-18-2010, 04:32 AM   #17
ArthurSittler
Member
 
Registered: Jul 2008
Distribution: Slackware
Posts: 124

Rep: Reputation: 31
a note on the philosophy of Unix and stdin, stdout, and stderr

Please let me know if this is helpful or unhelpful. This probably should be put in some tutorial rather than here.

There is an underlying philosophy in Unix. Trying to state it simply, everything is a file. So any program gets its input from the input file and writes its output to an output file. If it encounters any problems, it writes a message to an error file.

Because of this underlying philosophy, any C program automatically assumes that you will need an input file, output file, and error file. So the compiler quietly opens these three file handles for you automatically. (FILE *)stdin is opened for reading. (FILE *)stdout and (FILE *)stderr are opened for writing. Therefore, you do not need to open these three files explicitly. In fact, it is an error to attempt to do so.

By default, the input file stdin is connected to the keyboard and output files stdout and stderr are connected to the console. The console was originally a teletype keyboard and printer, but on newfangled modern computers is more likely to be a keyboard and a video display screen.

Writing output to an open file handle uses the file print with format function fprintf( FILE *pfOutfile, const char *pcFormatString, ... ), where pfOutfile is a file pointer to a file open for output, pcFormatString is a format string (usually a string constant) which specifies the format of the output possibly including format specifiers for additional variables, and the ellipsis (...) is a possibly empty list of variables to be written to the output file.
Since we usually write to stdout, the shortened print function

printf( const char *pcFormatString, ... );

is provided which is synonymous with

fprintf( stdout, const char *pcFormatString, ... );

That is, the message print line in the hello, world program,

printf( "Hello, world. Go suck pond water. \n" );

is actually identical in meaning to

fprintf( stdout, "Hello, world. Go suck pond water. \n" );

Similarly, the scan with format function

scanf( const char *pcFormatString, ... )

is synonymous to file scan with format function

fscanf( stdin, const char *pcFormatString, ... )

Though you do not need to open stderr, you do need to specify it and use the fprintf() function, as in

fprintf( stderr, "error detected!" );

So what is the difference between stdout and stderr? Well, if you redirect the output of your program to an output file when you actually run it, the stderr messages still go to the console. As a matter of style, you should use stdout for normal output from your program and send error messages to stderr. You can redirect the error output written to stderr separately from the redirection of the normal output to stdout.

Last edited by ArthurSittler; 05-18-2010 at 02:21 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
newbies being looked down upon ajzebuski General 15 10-29-2007 03:32 AM
ltmodem - please help, ive looked everywhere.... tbfirefox Linux - Hardware 8 07-11-2004 07:50 PM
Need Help - Looked Over Threads inescapeableus Linux - Newbie 5 04-15-2004 02:05 PM
Ive looked around at different distros.... now can someone characterize one for me? silverbullet Linux - Newbie 5 11-30-2003 04:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration