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. Its Really Easy to understand............. superb
View Tutorial          By: Regina at 2010-01-06 23:38:11

2. Thanks for this explanation. I'm not sure whether
View Tutorial          By: Venkatesh Challa at 2013-03-29 04:35:21

3. good
View Tutorial          By: yeoh at 2009-04-18 21:32:36

4. Timely info right when I needed it. Thanks.
View Tutorial          By: Electric Vehicles at 2008-12-10 15:15:25

5. Awesome post....
View Tutorial          By: Zeeshan Ali Ansari at 2012-11-24 06:35:20

6. I deploy a project in apache tomcat and backend to
View Tutorial          By: satish at 2010-08-04 05:31:59

7. very nice example
View Tutorial          By: lois at 2010-10-05 23:05:01

8. Hibernate with annotations and QBE api reduced our
View Tutorial          By: Andrew at 2011-04-29 10:34:26

9. hello sir,
i am create project autosubtitle

View Tutorial          By: Dilip Gauswami at 2013-12-01 06:46:34

10. Can any one help me writing the code...
In

View Tutorial          By: Prajwal at 2011-11-08 10:19:58