Thread: perror

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

    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.

  3. #3
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    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, 02:54 AM
  3. perror in C
    By vidya madala in forum C Programming
    Replies: 2
    Last Post: 11-11-2007, 08:40 AM
  4. errno --perror() problem
    By GanglyLamb in forum C Programming
    Replies: 10
    Last Post: 04-01-2003, 02:01 PM
  5. telnet
    By MrJake in forum C++ Programming
    Replies: 18
    Last Post: 11-13-2002, 06:21 PM