perror in C

This is a discussion on perror in C within the C Programming forums, part of the General Programming Boards category; Can anybody tell me the usage of perror in C language. Please give me a simple example along with its ...

  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,682
    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

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