Thread: perror in C

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    1

    perror in C

    Can anybody tell me the usage of perror in C language.
    Please give me a simple example along with its sample run of the program.Thanks.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    may be this one

    Code:
    #include <errno.h>
    
    int sock;
    
    if( ( sock = socket( AF_INET, SOCK_STREAM, 0 ) ) == -1 )
    {
        perror("socket");
        return -l;
    }
    When error occurs the global variable errno will be initialized with the error code.

    ssharish

Popular pages Recent additions subscribe to a feed