Error code: Difference between revisions

Content deleted Content added
No edit summary
Examples: minor cleanup
Line 5:
 
<source lang="c">
/* attempt to open file for reading */
FILE *fp = fopen("filename", "r");
/* if file cannot be opened, print error number and error string */
if (fp == NULL){
printf("Cannot open file, error %d, %s\n", errno, strerror(errno));
/* Alternatively one can use perror() to provide the above functionality */
perror("Cannot open file");
}
</source>