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. hello!!can anyone help me. can you send me the com
View Tutorial          By: denisse at 2008-01-07 05:40:25

2. i could not understood the left & right shift
View Tutorial          By: deepak singhal at 2013-07-10 03:37:44

3. Dear sir/madam

can you please show

View Tutorial          By: kgothatso at 2011-05-13 17:46:19

4. i am using the same code to read data from an RFID
View Tutorial          By: JayS at 2015-02-03 21:31:36

5. Hi,
i tried this way.that works perfectly.

View Tutorial          By: indu at 2009-06-08 03:13:51

6. it is 3 days since I searched resolution. It was h
View Tutorial          By: Daniel Costa at 2009-02-25 06:11:27

7. really understandable
but 'm expecting with

View Tutorial          By: rajkumar at 2008-03-14 03:53:21

8. constructors are not to be called. when you make a
View Tutorial          By: niyati at 2011-05-28 07:57:52

9. hey Mounika..did u solve ur problem ??if u did ple
View Tutorial          By: agnas at 2008-04-28 23:59:37

10. awesome.........
View Tutorial          By: tar at 2013-03-14 07:36:56