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. GOOD FOR BIGGENERS
View Tutorial          By: naresh at 2012-08-04 11:19:03

2. hi..it's very nice..can you send me the version fo
View Tutorial          By: daniel81 at 2010-02-11 09:19:36

3. that was gud example to explain abstract. i have d
View Tutorial          By: zishan at 2010-05-20 00:21:46

4. recursive programs that ask the user to enter the
View Tutorial          By: siyabonga at 2011-08-10 08:34:44

5. Hi Guys, thanks for sharing this... I have some mo
View Tutorial          By: Fins at 2011-12-14 04:40:09

6. Hi Friends.... Can you please send the working ver
View Tutorial          By: shafi at 2010-02-18 08:28:49

7. hi ,
this is prakash and i want to know how

View Tutorial          By: prakash at 2010-05-24 07:27:46

8. Thanks a lot lot lot for this... u saved me...
View Tutorial          By: Sourabh Idoorkar at 2011-06-10 04:25:10

9. I have no mounted the sd card, and I have the &quo
View Tutorial          By: Cgamboa at 2012-12-01 06:39:14

10. this site is really very useful.
it provide

View Tutorial          By: ankush bansal at 2009-11-12 08:34:13