主动的努力 [英] printig effort

查看:60
本文介绍了主动的努力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的振荡器程序修补了一个打印例程,并且一个接一个地问了一个问题。这不符合。但是它的错误比b
少。


#include< stdio.h>

#include< stdlib .h>


无效

prn(双输入)

{

FILE * fp;

double * inpt;

inpt =& input;

fopen(" data"," wt");

if((fwrite(inpt,sizeof(size_t),1,fp))!= EOF);

if((fclose(fp))!= EOF);

}


int

main(int argc,char * argv [])

{

双输入;

input = strtod(argv [1],NULL);

prn(argv [1]);

返回0;

}


主要与prn的参数不兼容。我把它改成了双倍。

哇。


比尔

I have patched together a print routine for my oscillator program and
one problem after another. This will not complie. But it has fewer errors
than it did.

#include <stdio.h>
#include <stdlib.h>

void
prn (double input)
{
FILE *fp;
double *inpt;
inpt = &input;
fopen ("data", "wt");
if ((fwrite (inpt, sizeof (size_t), 1, fp)) != EOF);
if ((fclose (fp)) != EOF);
}

int
main (int argc, char *argv[])
{
double input;
input = strtod (argv[1], NULL);
prn (argv[1]);
return 0;
}

in main the argument to prn is incompatible. I changed it to a double.
Whew.

Bill

推荐答案

On Sun,2008年6月8日02:14:49 GMT,Bill Cunningham < no **** @ nspam.com>

写道:
On Sun, 08 Jun 2008 02:14:49 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:

我已经为我的振荡器程序修补了一个打印例程
接下来的一个问题。这不符合。但它的错误比它少。

#include< stdio.h>
#include< stdlib.h>

void
prn(双输入)
$
FILE * fp;

double * inpt;

inpt =&输入;

fopen(" data"," wt");
I have patched together a print routine for my oscillator program and
one problem after another. This will not complie. But it has fewer errors
than it did.

#include <stdio.h>
#include <stdlib.h>

void
prn (double input)
{
FILE *fp;
double *inpt;
inpt = &input;
fopen ("data", "wt");



您正在以文本模式打开文件。

You are opening the file in text mode.


if((fwrite(inpt,sizeof( size_t),1,fp))!= EOF);
if ((fwrite (inpt, sizeof (size_t), 1, fp)) != EOF);



但是你要写一个二进制值。


此外,fwrite返回一个size_t,保证是

无符号。另一方面,EOF保证是负面的。

尝试比较两者并不是你想要做的。


然而,从那以后分号代表一个空语句,它不会因为if评估为true还是false而无关紧要。如果是真的,那你就不会做任何事情。如果它是假的,你跳过空的陈述仍然没有

没有。

But you are writing a binary value to it.

Furthermore, fwrite returns a size_t which is guaranteed to be
unsigned. EOF, on the other hand, is guaranteed to be negative.
Attempting to compare the two is not what you want to do.

And yet, since the semicolon represents an empty statement, it doesn''t
matter whether the if evaluates to true or false. If it is true, you
do nothing. If it is false, you skip the empty statement and still do
nothing.


if((fclose(fp))!= EOF );
if ((fclose (fp)) != EOF);



同上。

Ditto.


>}

int
main(int argc,char * argv [])
$
double input;

input = strtod(argv [1],NULL);

prn(argv [1]);
>}

int
main (int argc, char *argv[])
{
double input;
input = strtod (argv[1], NULL);
prn (argv[1]);



prn需要一倍。 argv [1]是一个指针。你为什么要通过

argv [1]当你把所有的麻烦都转换成它的价值时,你会把b $ b指向一个双倍的输入?

prn takes a double. argv[1] is a pointer. Why are you passing
argv[1] when you went to all the trouble to convert the value it
points at to a double in input?


返回0;
}

主要与prn的参数不兼容。我把它改成了双。
return 0;
}

in main the argument to prn is incompatible. I changed it to a double.



不,你没有。

删除del电子邮件

No you didn''t.
Remove del for email




" Barry Schwarz" < sc ****** @ dqel.com写信息

新闻:bq ************************ ******** @ 4ax.com ...

"Barry Schwarz" <sc******@dqel.comwrote in message
news:bq********************************@4ax.com...

您正在以文本模式打开文件。
You are opening the file in text mode.

> if((fwrite(inpt,sizeof(size_t),1,fp))!= EOF);
> if ((fwrite (inpt, sizeof (size_t), 1, fp)) != EOF);



但是你正在为它写一个二进制值。


But you are writing a binary value to it.



之前我从未真正写过文本模式。我不知道该怎么做。

I''ve never really written to text mode before. I don''t know what to do.


此外,fwrite返回一个size_t,保证是

unsigned。另一方面,EOF保证是负面的。

尝试比较两者并不是你想要做的。
Furthermore, fwrite returns a size_t which is guaranteed to be
unsigned. EOF, on the other hand, is guaranteed to be negative.
Attempting to compare the two is not what you want to do.



我必须要做这样的事情。


size_t t;

if(b) (t = fwrite(inpt,sizeof(size_t),1,fp))== NULL)

puts(" error");

I must want to do something like this.

size_t t;
if ((t=fwrite ( inpt,sizeof(size_t),1,fp))==NULL)
puts("error");


然而,由于分号代表一个空语句,因此无论是否为$或者
是否评估为true或false。如果是真的,那你就不会做任何事情。如果它是假的,你跳过空的陈述仍然没有

没有。
And yet, since the semicolon represents an empty statement, it doesn''t
matter whether the if evaluates to true or false. If it is true, you
do nothing. If it is false, you skip the empty statement and still do
nothing.

> if((fclose(fp))!= EOF);
> if ((fclose (fp)) != EOF);



同上。


Ditto.


>>}

int
main(int argc,char * argv [])
{
双输入;
input = strtod(argv [1],NULL);
prn(argv [1 ]);
>>}

int
main (int argc, char *argv[])
{
double input;
input = strtod (argv[1], NULL);
prn (argv[1]);



prn需要一倍。 argv [1]是一个指针。你为什么要通过

argv [1]当你把所有的麻烦都转换成它的价值时,你会把b $ b指向一个双倍的输入?


prn takes a double. argv[1] is a pointer. Why are you passing
argv[1] when you went to all the trouble to convert the value it
points at to a double in input?


>返回0;
}

在主要的prn参数是不兼容的。我把它改成了双。
> return 0;
}

in main the argument to prn is incompatible. I changed it to a double.



不,你没有。


No you didn''t.



我不是吗?那时我不需要strtod功能吗?


我很高兴有人知道他们在做什么因为我确定

don '' T。我也忘记了。我以前用fwrite进行过错误检查。但是

一直都是这样。


非常感谢


比尔

I didn''t? Do I not need the strtod function there then?

I''m so glad somebody out there knows what they''re doing because I sure
don''t. And I forget too. I''ve used error checking with fwrite before. But
its been along time.

Thanks much

Bill




" Barry Schwarz" < sc ****** @ dqel.com写信息

新闻:bq ************************ ******** @ 4ax.com ...


[snip]

"Barry Schwarz" <sc******@dqel.comwrote in message
news:bq********************************@4ax.com...

[snip]

prn需要双倍。 argv [1]是一个指针。你为什么要通过

argv [1]当你把所有的麻烦都转换成它的价值时,你会把b $ b指向一个双倍的输入?
prn takes a double. argv[1] is a pointer. Why are you passing
argv[1] when you went to all the trouble to convert the value it
points at to a double in input?

>返回0;
}
> return 0;
}



我是否不想使用strtod将argv [1]转换为double?如果

有人输入字符串怎么办?这是采取什么。是否需要进行错误检查

这里?


比尔

Do I not want to use strtod to convert argv[1] to a double? What if
someone entered a string? Which is what is taken. Is an error check needed
here?

Bill


这篇关于主动的努力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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