P
ptn
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
I was messing around with math.h and I got this error:
"""
/tmp/ccefZYYN.o: In function `digcount':
itos.c
itos.c
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