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. some more examples should be given...
View Tutorial          By: flora at 2010-12-08 03:32:50

2. Hi friends i am the beginner ..
please guid

View Tutorial          By: Jigar at 2013-05-20 11:04:03

3. any body who have a full source code of the progra
View Tutorial          By: progra at 2013-02-11 12:37:34

4. i cant understand the concept.please mail me the f
View Tutorial          By: nirmal at 2012-12-17 06:53:14

5. thanks. it helped a lot!
View Tutorial          By: lateforbus at 2013-04-25 03:35:24

6. hi i am shahid i have made SMS application in j2me
View Tutorial          By: shahid khan at 2012-06-18 13:19:06

7. Nothing that hasn't been said before, but I wasn't
View Tutorial          By: Calvin at 2010-03-22 20:43:10

8. Able to connect to mobile
Unable to send me

View Tutorial          By: Prashant at 2011-04-24 01:16:27

9. helpfull !!!!
View Tutorial          By: Anonymous at 2009-05-12 03:48:15

10. i connect my program to my sql and create table. a
View Tutorial          By: Santosh Agrawal at 2013-04-08 13:00:56