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. hi could u tell me how to download a file using se
View Tutorial          By: akki at 2013-02-19 05:52:03

2. feel happy but i want to database tables also
View Tutorial          By: sisira at 2013-06-05 13:26:51

3. I am not able to open the rar file, can you please
View Tutorial          By: Chandra at 2008-08-07 10:35:59

4. example is good for understand what is the functio
View Tutorial          By: Ankit Shukla at 2009-09-17 15:25:17

5. It's so crazy to the adventures of J2ME side and w
View Tutorial          By: jaikarthik at 2009-01-18 23:42:42

6. Indent your code, man.
View Tutorial          By: Jenga at 2009-02-16 17:30:07

7. Very nice.
Thanks

View Tutorial          By: Kaviya at 2015-02-23 13:48:15

8. how to read any xml file or i want to a universal
View Tutorial          By: shankar lal at 2014-09-29 12:40:20

9. What about object bean with view scope?
View Tutorial          By: Awo at 2012-02-11 12:17:36

10. can u give video of this code how it work & w
View Tutorial          By: vishal mande at 2015-04-04 08:20:30