Comment on Tutorial - perror() Function - example program in C By Lakshmi



Comment Added by : John Morrison

Comment Added at : 2010-03-28 14:55:07

Comment on Tutorial : perror() Function - example program in C By Lakshmi
Nice example. I think this is more idiomatic tho'.


/* Demonstration of error handling with perror() and errno. */

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char** argv)
{
FILE *fp;

if (fp = fopen(argv[1], "r"))
{
printf("File %s opened for reading.\n", argv[1]);
fclose(fp);
}
else
{
perror("You goofed!");
printf("errno = %d.\n", errno);
exit(1);
}
return 0 ;
}


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. It's a useful explanation, but i wanna known how c
View Tutorial          By: Noe Marin at 2008-01-25 13:27:57

2. The following exception are raised in send sms in
View Tutorial          By: Vikram Subbiah at 2010-04-12 02:09:36

3. Showing code with quote tags is pretty rubbish. :/
View Tutorial          By: Daniel Jonsson at 2011-09-01 14:01:04

4. Hi,.
No Change yaar, Im still getting the s

View Tutorial          By: Dinesh Rajendiran at 2012-03-23 05:19:06

5. i want to open pdf file from sd card and i dont wa
View Tutorial          By: Karan Mavadhiya at 2013-01-30 12:02:30

6. To RUN this code, follow below steps


View Tutorial          By: Ajay at 2010-09-04 03:01:24

7. I am using MacOSX 10.5.4 and only enabling the mod
View Tutorial          By: Sachin at 2011-03-26 00:23:05

8. Dude,
Atleast indent and try to make sense

View Tutorial          By: Phani at 2015-03-19 16:51:57

9. can u give a gud example on command line arguments
View Tutorial          By: shravan at 2010-04-09 23:11:18

10. What exactly is d directry for d folder Media?? It
View Tutorial          By: Oraclematrix at 2012-01-15 21:40:54