ceil() and log10() - undefined?

Discussion in 'C Programming' started by ptn, Oct 3, 2007.

  1. ptn

    ptn Guest

    Hi everyone,

    I was messing around with math.h and I got this error:

    """
    /tmp/ccefZYYN.o: In function `digcount':
    itos.c:(.text+0x103): undefined reference to `log10'
    itos.c:(.text+0x111): undefined reference to `ceil'
    collect2: ld returned 1 exit status

    shell returned 1
    """

    It can't be that log10() and ceil() aren't defined, because math.h
    takes care of that. I admit that I have no idea what .text+0x111/.text
    +0x103 means

    The complete code is here:

    # include <stdio.h>
    # include <malloc.h>
    # include <math.h>

    int digcount(int num); // counts the digits of <num>

    main()
    // transform a number to a string
    {
    int num, fact, dig, digits, i;
    char *s;

    scanf("%d", &num);
    digits = digcount(num);
    s = (char *) malloc((digits + 1) * sizeof(char)); // assign just
    enough space
    s += (digits - 1); // go to the last address of the memory space
    assigned
    *s-- = '\0'; // mark the end of the string
    for (i = 0; i < digits; i++) {
    dig = num % 10;
    num /= 10;
    *s-- = '0' + dig; // store digit by digit
    }
    printf("\"%s\"\n", ++s); // after the for, s is pointing to the
    addres before the start of the string
    }

    int digcount(int num)
    /* N = trunc(log(x), 0) + 1, where N is the number of digits of x */
    {
    double ans;

    ans = log10(num);
    ans = ceil(ans);
    return (int) ans;
    }

    Any ideas are welcome.
    (I'm using Vim + gcc under Ubuntu Feisty Fawn)

    Thanks,

    Pablo Torres Navarrete
    ptn, Oct 3, 2007
    #1
    1. Advertising

  2. ptn

    Guest

    On Oct 3, 8:55 am, ptn <> wrote:
    > Hi everyone,
    >
    > I was messing around with math.h and I got this error:
    >
    > """
    > /tmp/ccefZYYN.o: In function `digcount':
    > itos.c:(.text+0x103): undefined reference to `log10'
    > itos.c:(.text+0x111): undefined reference to `ceil'
    > collect2: ld returned 1 exit status
    >
    > shell returned 1
    > """
    >
    > It can't be that log10() and ceil() aren't defined, because math.h
    > takes care of that. I admit that I have no idea what .text+0x111/.text
    > +0x103 means
    >
    > The complete code is here:
    >
    > # include <stdio.h>
    > # include <malloc.h>
    > # include <math.h>
    >
    > int digcount(int num); // counts the digits of <num>
    >
    > main()
    > // transform a number to a string
    > {
    > int num, fact, dig, digits, i;
    > char *s;
    >
    > scanf("%d", &num);
    > digits = digcount(num);
    > s = (char *) malloc((digits + 1) * sizeof(char)); // assign just
    > enough space
    > s += (digits - 1); // go to the last address of the memory space
    > assigned
    > *s-- = '\0'; // mark the end of the string
    > for (i = 0; i < digits; i++) {
    > dig = num % 10;
    > num /= 10;
    > *s-- = '0' + dig; // store digit by digit
    > }
    > printf("\"%s\"\n", ++s); // after the for, s is pointing to the
    > addres before the start of the string
    >
    > }
    >
    > int digcount(int num)
    > /* N = trunc(log(x), 0) + 1, where N is the number of digits of x */
    > {
    > double ans;

    Too difficult question for me

    > ans = log10(num);
    > ans = ceil(ans);
    > return (int) ans;
    >
    > }
    >
    > Any ideas are welcome.
    > (I'm using Vim + gcc under Ubuntu Feisty Fawn)
    >
    > Thanks,
    >
    > Pablo Torres Navarrete
    , Oct 3, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SpaceCowboy
    Replies:
    6
    Views:
    1,081
    Josef Garvi
    Aug 15, 2003
  2. RB Smissaert

    log10

    RB Smissaert, Apr 15, 2006, in forum: C++
    Replies:
    2
    Views:
    452
    RB Smissaert
    Apr 15, 2006
  3. zlotawy

    ceil and floor

    zlotawy, Sep 15, 2007, in forum: VHDL
    Replies:
    4
    Views:
    685
  4. ptn

    ceil() and log10() - undefined?

    ptn, Oct 3, 2007, in forum: C Programming
    Replies:
    14
    Views:
    7,634
    Keith Thompson
    Oct 4, 2007
  5. Test

    ceil() and int values

    Test, Oct 13, 2013, in forum: C Programming
    Replies:
    26
    Views:
    373
    Ben Bacarisse
    Oct 26, 2013
Loading...

Share This Page