ceil()和log10() - 未定义? [英] ceil() and log10() - undefined?

查看:402
本文介绍了ceil()和log10() - 未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在乱搞math.h而且我收到了这个错误:


"""

/tmp/ccefZYYN.o:在函数`digcount'':

itos.c :(。text + 0x103):未定义引用`log10''

itos.c :(。text + 0x111):未定义引用`ceil''

collect2:ld返回1退出状态


shell返回1

"""


不能定义log10()和ceil(),因为math.h

负责处理。我承认我不知道是什么.text + 0x111 / .text

+ 0x103意味着


完整代码在这里:


#include< stdio.h>

#include< malloc.h>

#include< math.h>


int digcount(int num); //计算< num>的数字


main()

//将数字转换为字符串

{

int num,fact,dig,digits,i;

char * s;


scanf("%d" ,& num);

digits = digcount(num);

s =(char *)malloc((digits + 1)* sizeof(char)); //只分配

足够的空间

s + =(数字 - 1); //转到内存空间的最后一个地址

分配

* s-- =''\'''; //标记字符串的结尾

for(i = 0; i< digits; i ++){

dig = num%10;

num / = 10;

* s-- =''0''+ dig; //逐位存储

}

printf(" \"%s \" \ n",++ s); //在for之后,s指向字符串开头之前的

地址

}


int digcount( int num)

/ * N = trunc(log(x),0)+ 1,其中N是x * /

的数字位数{

double ans;


ans = log10(num);

ans = ceil(ans);

return(int)ans;

}


欢迎任何想法。

(我正在使用Vim + gcc Ubuntu Feisty Fawn)


谢谢,


Pablo Torres Navarrete

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

推荐答案

10月3日上午8:55,ptn< tn.pa ... @ gmail.comwrote:
On Oct 3, 8:55 am, ptn <tn.pa...@gmail.comwrote:

大家好,


我正在乱搞math.h,我收到了这个错误:


"""

/tmp/ccefZYYN.o:在函数`digcount'':

itos.c :(。text + 0x103):未定义引用`log10''

itos.c :(。text + 0x111):未定义的引用t o`ceil''

collect2:ld返回1退出状态


shell返回1

"""


不能定义log10()和ceil(),因为math.h

负责处理。我承认我不知道是什么.text + 0x111 / .text

+ 0x103意味着


完整代码在这里:


#include< stdio.h>

#include< malloc.h>

#include< math.h>


int digcount(int num); //计算< num>的数字


main()

//将数字转换为字符串

{

int num,fact,dig,digits,i;

char * s;


scanf("%d" ,& num);

digits = digcount(num);

s =(char *)malloc((digits + 1)* sizeof(char)); //只分配

足够的空间

s + =(数字 - 1); //转到内存空间的最后一个地址

分配

* s-- =''\'''; //标记字符串的结尾

for(i = 0; i< digits; i ++){

dig = num%10;

num / = 10;

* s-- =''0''+ dig; //逐位存储

}

printf(" \"%s \" \ n",++ s); //在for之后,s指向字符串开头之前的

地址


}


int digcount(int num)

/ * N = trunc(log(x),0)+ 1,其中N是x * /

的位数{

double ans;
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;


}


任何想法欢迎。

(我在Ubuntu Feisty Fawn下使用Vim + gcc)


谢谢,


Pablo Torres Navarrete
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



这篇关于ceil()和log10() - 未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆