Thread: getdelim()

  1. #1
    Registered User
    Join Date
    Apr 2009
    Location
    Turkey
    Posts
    12

    getdelim()

    For a string problem, I tried to use getdelim function and I get this warning :

    warning: implicit declaration of function ‘getdelim’

    I guess it's a library problem although I have tried to include some of them.

    Any suggestion?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I've never heard of it. You need to find out what header file to include, and what, if any, linker files (.dll, .so, .lib, etc) are needed to access the function.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Apr 2009
    Location
    Turkey
    Posts
    12
    Quote Originally Posted by Sebastiani View Post
    I've never heard of it. You need to find out what header file to include, and what, if any, linker files (.dll, .so, .lib, etc) are needed to access the function.
    Yeah, I'm trying to find that header file. I actually found some stuff like including #define _GNU_SOURCE ...but that didn't work.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    You need to define _GNU_SOURCE before including stdio.h. Generally this is done on the commandline, as in "cc -D_GNU_SOURCE", but you could also do it at the very top of your source file.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Location
    Turkey
    Posts
    12
    Quote Originally Posted by cas View Post
    You need to define _GNU_SOURCE before including stdio.h. Generally this is done on the commandline, as in "cc -D_GNU_SOURCE", but you could also do it at the very top of your source file.
    Well i tried to include it before including the stdio.h and I get this error , interesting

    error: pointer targets in passing argument 2 of ‘getdelim’ differ in signedness

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by zhankal View Post
    Well i tried to include it before including the stdio.h and I get this error , interesting

    error: pointer targets in passing argument 2 of ‘getdelim’ differ in signedness
    Post your code. Most likely you are passing a pointer to unsigned char, and the function expects a regular char, but it's not possible to say without seeing the code.

    --
    Mats
    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.

  7. #7
    Registered User
    Join Date
    Apr 2009
    Location
    Turkey
    Posts
    12
    Quote Originally Posted by matsp View Post
    Post your code. Most likely you are passing a pointer to unsigned char, and the function expects a regular char, but it's not possible to say without seeing the code.

    --
    Mats
    Code:
    #define _GNU_SOURCE
    #include <stdio.h>
    #include <stdlib.h>
    
    
    
    int main()
    {
      int bytes_read;
      int nbytes = 100;
      char *my_string;
    
      puts ("Please enter a line of text.");
    
      /* These 2 lines are the heart of the program. */
      my_string = (char *) malloc (nbytes + 1);
      bytes_read = getdelim (&my_string, &nbytes,'\n', stdin);
    
    
      if (bytes_read == -1)
        {
          puts ("ERROR!");
        }
      else
        {
          puts ("You typed:");
          puts (my_string);
        }
    
      return 0;
    }
    This is just a simple code that i tried the use of getdelim.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Parameter 2 in getdelim is a pointer to size_t, so your nbytes should be of the type size_t (note that int and size_t may be different size as well as different sign - and if it's different size you'd get more problems even if you use unsigned int and the compiler doesn't give this particular warning [it probably will give some other warning tho']).

    --
    Mats
    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.

  9. #9
    Registered User
    Join Date
    Apr 2009
    Location
    Turkey
    Posts
    12
    Quote Originally Posted by matsp View Post
    Parameter 2 in getdelim is a pointer to size_t, so your nbytes should be of the type size_t (note that int and size_t may be different size as well as different sign - and if it's different size you'd get more problems even if you use unsigned int and the compiler doesn't give this particular warning [it probably will give some other warning tho']).

    --
    Mats
    For just to get rid of this warnings, in what else way can i read the string? (the problem is i need to care about whitespaces and i don't know the size of input)

Popular pages Recent additions subscribe to a feed