Using strndup

This is a discussion on Using strndup within the C Programming forums, part of the General Programming Boards category; I'd like to know how to use this function in my program. I've included string.h but I still get this ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    36

    Using strndup

    I'd like to know how to use this function in my program. I've included string.h but I still get this warning when compiling.

    warning: incompatible implicit declaration of built-in function ‘strndup'
    I'd appreciate some help with this. Thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Implicit declaration means that it couldn't find it in the header file. Since your compiler thinks it's built-in that's a good start (i.e., you are on a system that has it in the first place). We've had something similar here before; if you read the man page on strndup it says that you need to have
    Code:
    #define _GNU_SOURCE
    before you include string.h if you want to get the extra fancy functions included.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    36
    Ah, thank you. I actually tried defining __USE_GNU because that's what's in my /usr/inlude/string.h

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trouble with strndup function
    By Kinasz in forum C Programming
    Replies: 6
    Last Post: 07-26-2004, 06:45 AM

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