Velocity Reviews > ceil() and log10() - undefined?

ceil() and log10() - undefined?

ptn
Guest
Posts: n/a

 10-03-2007
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

pateldm15@rediffmail.com
Guest
Posts: n/a

 10-03-2007
On Oct 3, 8:55 am, ptn <(E-Mail Removed)> 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

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules