如何调用仅包含“const char * a”的函数? [英] How do I call a function taking only "const char *a"

查看:105
本文介绍了如何调用仅包含“const char * a”的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我对C来说是全新的,并且如何处理不同类型的问题还有一个问题。

的变量。


我有一个你打电话的功能:


double calcdiff(const char * old,const char * new)

>
我启动两个双打,我需要转换才能调用

以上的功能。我该怎么做呢?


谢谢

Hi all,

I''m totally new to C and hava a problem how to handle different types
of variables.

I have a function which which you call by:

double calcdiff(const char *old, const char *new)

I have at start two doubles that I need to convert in order to call the
above function. How would I go about to do that?

Thanks

推荐答案

RoughRyde写道:
RoughRyde wrote:

我对C来说是全新的,并且有一个问题如何处理不同类型

的变量。
I''m totally new to C and hava a problem how to handle different types
of variables.



[获得一本体面的C书。通过新闻组进行滴水是很慢的。]

[Get a decent C book. Dripfeeding via newsgroup is slow.]


我有一个你可以调用的函数:


double calcdiff(const char * old,const char * new)
I have a function which which you call by:

double calcdiff(const char *old, const char *new)



你有一个名为`calcdiff`的函数,它返回一个`double`和

它需要两个/ strings /作为参数?


有些东西坏了。

You have a function called `calcdiff` which returns a `double` and
it takes two /strings/ as arguments?

Something is broken.


我在开始时需要转换两个双打为了调用

以上的功能。我该怎么做呢?
I have at start two doubles that I need to convert in order to call the
above function. How would I go about to do that?



如果你想获得双值的字符串表示,

可能你应该使用`sprintf`。但我先申请伯明翰

原则[1]。如果`calcdiff`需要两个代表

的字符串,将它们变成双精度数,减去它们,然后返回

结果,那么它就是一个很好的naff函数(如果它不是,它是'b $ b给了一个naff名字:你失败的头,我赢的尾巴)。


[1]"我不会从这里开始。


-

Chris" Perikles胜利 Dollin

你服务的对象是谁,你信任谁? / Crusade /

If you want to get the string representation of a double value,
probably you should use `sprintf`. But I''d apply the Birmingham
principle [1] first. If `calcdiff` takes two strings representing
doubles, turns them into doubles, subtracts them, and returns the
result, then it''s a pretty naff function (and if it doesn''t, it''s
been given a naff name: heads you lose, tails I win).

[1] "I wouldn''t start from here."

--
Chris "Perikles triumphant" Dollin
"Who do you serve, and who do you trust?" /Crusade/




" RoughRyde" < fr ********** @ gmail.comwrote in message

news:11 ******************** *@16g2000cwy.googlegrou ps.com ...

"RoughRyde" <fr**********@gmail.comwrote in message
news:11*********************@16g2000cwy.googlegrou ps.com...

大家好,


我是C的新手和hava一个问题如何处理不同类型

的变量。


我有一个函数,你可以通过以下方式调用:


double calcdiff(const char * old,const char * new)


我启动两个双打,我需要转换才能调用

以上功能。我该怎么做呢?


谢谢
Hi all,

I''m totally new to C and hava a problem how to handle different types
of variables.

I have a function which which you call by:

double calcdiff(const char *old, const char *new)

I have at start two doubles that I need to convert in order to call the
above function. How would I go about to do that?

Thanks



你还没有给出足够的信息。这个功能实际上是什么?
呢?输入应该是什么格式?


例如:


d = calcdiff(" 3.555"," 1.7E) -16");





d = calcdiff(三个半,pi);


如果它只是前者,并且该功能正如其名称

所暗示的那样,为什么不用它:

d = var1 - var2;


-

Fred L. Kleinschmidt

波音助理技术研究员

技术架构师,软件重用项目

You haven''t given enough information. What does the function actually
do? What format are the inputs supposed to be in?

For example:

d = calcdiff( "3.555", "1.7E-16" );

or

d = calcdiff( "three and a half", "pi" );

If it is just the former, and the function does exactly what its name
implies, why don''t you just use:

d = var1 - var2;

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project


我想要的是计算两个日期之间的天数。

鉴于我对CI的了解有限,在网上找到了一个这样的例子

,如下所示。问题是我给了indata作为双打。

所以为了轻松解决这个问题,我只想转换那些

双打。


但是如果你对如何解决这个问题有任何其他的建议,那就是 b
赞赏。


double calcdiff(const char * old,const char * new)

{

struct tm t1 = {0};

struct tm t2 = {0};

time_t tt1 = {0};

time_t tt2 = {0};


stotm(& t1,old) ;

stotm(& t2,new);

tt1 = mktime(& t1);

tt2 = mktime(& t2 );

if(tt1!= -1&& tt2!= -1)

{

long day = 0;

double d = difftime(tt1,tt2);

if(d <0)d * = -1.0;

day = d / 86400;

返回日;

}

其他

{

返回0 ;

}


}


void stotm(struct tm * p,const char * s)

{

int i;

struct tm blank = {0};

* p =空白;


for(i = 0;我< 4; i ++)

{

p-> tm_year * = 10;

p-> tm_year + = * s ++ - ''0' ';

}

p-> tm_year - = 1900;

for(i = 0; i< 2; i ++)

{

p-> tm_mon * = 10;

p-> tm_mon + = * s ++ - ''0'';

}

--p-> tm_mon;

p-> tm_mday = 10 *(* s ++ - ''0'') ;

p-> tm_mday + = * s ++ - ''0'';


}


Fred Kleinschmidt skrev:
What I want is to calculate the number of days between two dates.
Given my limited knowledge of C I found an example of this on the web
which looked as below. The problem is that I''m given indata as doubles.
So in order to take the easy way out I just wanted to convert those
doubles.

But if you have any other suggestions on how to solve this that''s
appreciated.

double calcdiff(const char *old, const char *new)
{
struct tm t1 = {0};
struct tm t2 = {0};
time_t tt1 = {0};
time_t tt2 = {0};

stotm(&t1, old);
stotm(&t2, new);
tt1 = mktime(&t1);
tt2 = mktime(&t2);
if(tt1 != -1 && tt2 != -1)
{
long day = 0;
double d = difftime(tt1, tt2);
if(d < 0) d *= -1.0;
day = d / 86400;
return day;
}
else
{
return 0;
}

}

void stotm(struct tm *p, const char *s)
{
int i;
struct tm blank = {0};
*p = blank;

for(i = 0; i < 4; i++)
{
p->tm_year *= 10;
p->tm_year += *s++ - ''0'';
}
p->tm_year -= 1900;
for(i = 0; i < 2; i++)
{
p->tm_mon *= 10;
p->tm_mon += *s++ - ''0'';
}
--p->tm_mon;
p->tm_mday = 10 * (*s++ - ''0'');
p->tm_mday += *s++ - ''0'';

}

Fred Kleinschmidt skrev:

" RoughRyde" < fr ********** @ gmail.comwrote in message

news:11 ******************** *@16g2000cwy.googlegrou ps.com ...
"RoughRyde" <fr**********@gmail.comwrote in message
news:11*********************@16g2000cwy.googlegrou ps.com...

大家好,


我是C的新手和hava一个问题如何处理不同类型

的变量。


我有一个函数,你可以通过以下方式调用:


double calcdiff(const char * old,const char * new)


我启动两个双打,我需要转换才能调用

以上功能。我该怎么做呢?


谢谢
Hi all,

I''m totally new to C and hava a problem how to handle different types
of variables.

I have a function which which you call by:

double calcdiff(const char *old, const char *new)

I have at start two doubles that I need to convert in order to call the
above function. How would I go about to do that?

Thanks



你还没有给出足够的信息。这个功能实际上是什么?
呢?输入应该是什么格式?


例如:


d = calcdiff(" 3.555"," 1.7E) -16");





d = calcdiff(三个半,pi);


如果它只是前者,并且该功能正如其名称

所暗示的那样,为什么不用它:

d = var1 - var2;


-

Fred L. Kleinschmidt

波音助理技术研究员

技术架构师,软件重用项目

You haven''t given enough information. What does the function actually
do? What format are the inputs supposed to be in?

For example:

d = calcdiff( "3.555", "1.7E-16" );

or

d = calcdiff( "three and a half", "pi" );

If it is just the former, and the function does exactly what its name
implies, why don''t you just use:

d = var1 - var2;

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project


这篇关于如何调用仅包含“const char * a”的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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