perror

This is a discussion on perror within the C Programming forums, part of the General Programming Boards category; Code: if( (fp = fopen(name_ptr, mode_ptr)) == NULL){ perror(name_ptr); exit(1); } For some reason the fopen failed, but perror displayed ...

  1. #1
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523

    perror

    Code:
    if( (fp = fopen(name_ptr, mode_ptr)) == NULL){
    		perror(name_ptr);
    		exit(1);
    	}
    For some reason the fopen failed, but perror displayed the message "no error". Does anyone know why, after all fopen returns NULL when there is an error so perror should report it.
    It only did this the once and I was just wondering why.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,495
    > perror(name_ptr);
    Since perror prints out this string, then the text for the error message - I can only assume that if you saw no filename printed, then that was the cause of the problem.

    Namely, trying to open an un-named file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    That makes sense, thanks salem
    All spelling mistakes, syntatical errors and stupid comments are intentional.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 01:54 AM
  3. perror in C
    By vidya madala in forum C Programming
    Replies: 2
    Last Post: 11-11-2007, 07:40 AM
  4. errno --perror() problem
    By GanglyLamb in forum C Programming
    Replies: 10
    Last Post: 04-01-2003, 01:01 PM
  5. telnet
    By MrJake in forum C++ Programming
    Replies: 18
    Last Post: 11-13-2002, 05:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21