Cooler_

errno example

Oct 21st, 2014
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. // just another example by Cooler_
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. FILE *
  8. open_sesame (char *name)
  9. {
  10.   FILE *stream=NULL;
  11.  
  12.   errno = 0;
  13.   stream = fopen (name, "rx");
  14.   if (stream == NULL)
  15.   {
  16.       fprintf (stderr, " File:%s \n %s\n", name, strerror (errno));
  17.       exit (1);
  18.   }
  19.   else
  20.     return stream;
  21. }
  22.  
  23. int main()
  24. {
  25.  
  26.  FILE *startrek=open_sesame("mano_jones_.txt");
  27.  
  28. // ... etc
  29.  
  30.  
  31.  exit(0);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment