User Tools

Site Tools


c:stdio.h:perror

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdio.h:perror [2024/02/16 01:05] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +
 +====== perror ======
 +<code c>
 +    void perror(const char *str);
 +</code>
 +
 +Prints str (if non-null) and strerror(errno) to standard error as would:
 +<code c>
 +fprintf(stderr, "%s: %s\n", (s != NULL ? s : ""), strerror(errno))
 +</code>
 +===== C Sourcecode Example =====
 +<code c>
 +/* 
 + * perror example code
 + * http://code-reference.com/c/stdio.h/perror 
 + */
 +
 +#include <stdio.h> /* including standard library */
 +//#include <windows.h> /* uncomment this for Windows */
 +
 +
 +int main ( void )
 +{
 +FILE *stream;
 +
 +stream = fopen("test_not_exists.txt","r");
 +
 +if (stream == 0) {
 +perror("Here comes the perror code ->");
 +return 1;
 +}
 +
 +printf("its all fine\n");
 +
 +fclose (stream);
 +return 0;
 +
 +}
 +</code>
 +
 +=== output ===
 +   ./perror 
 +    Here comes the perror code ->: No such file or directory
 + 
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/perror.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz