c - Displaying standard error messages -


I'm just testing a small program that I want to test.

I am thinking that there is a way to use stderr to display a real error.

For example, if the file does not exist, there is a standard error that I can display.

I am using stderr, and I thought using it, what can I do to see the real error.

For example. If the file does not exit

I hope that I am clear from my question.

Many thanks for any advice.

  #include & lt; Stdio.h & gt; #include & lt; String.h & gt; Int main (zero) {four buffers [100] = {'\ 0'}; / * Declared and clean buffer * / file * FP; Int len_of_buff = 0; Fp = fopen ("licenseURL.txt", "r"); If (fp == NULL) {fprintf (stderr, "There was an error opening a file ???"); Exit (1); } Fgets (buffer, size (buffer), FP); Len_of_buff = strlen (buffer); Buffer [len_of_buff + 1] = '\ 0'; / * Null terminate * / printf ("URL: [% s] \ n", buffer); Fclose (fp); }  

Call your fprintf (stderr, ...) with:

  Fault ("Open File");  

(stderr is just a stream to send an error message so that they are not mixed with normal program output - if you are redirecting to a file or similar).


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -