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. why the code had error in status???
View Tutorial          By: matuz at 2011-11-13 11:35:34

2. Awsome...Example...
View Tutorial          By: sitakanta at 2011-12-05 12:22:03

3. i want full information of java topics
View Tutorial          By: mahesh at 2008-12-14 23:38:50

4. .. nice one ..
.. aNg gLing nka2'amazing .

View Tutorial          By: ma'kHuLet at 2010-01-19 19:25:19

5. What is this....for simple question every one was
View Tutorial          By: Kaify at 2011-07-27 21:35:52

6. Very helpful.
View Tutorial          By: Krishna at 2012-06-14 10:25:00

7. I went befly through this, it is woderful, usefull
View Tutorial          By: Mallikarjuna.N at 2009-11-28 11:41:58

8. Hi ! do u know have use FileOutputStream in Surfac
View Tutorial          By: lukas at 2011-07-18 16:55:20

9. It is very simple and understandable tutorial, the
View Tutorial          By: Syed Turab at 2010-03-09 07:27:15

10. more daitlled coding for me
View Tutorial          By: fred at 2008-07-15 05:56:49