成功!我认为 [英] success! I think

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

问题描述

我开始考虑今天在算术运算符上阅读

turtorials之后我可以使用文件的一些练习并且让自己感到困惑并且决定

这样做。

从linux中取mv命令移动并重命名文件,将其读取为

binary并将其写为文本。经过一些编译器编译后,我编译了一下,我认为它确实要我想要它。


#include< stdio.h>


int main(无效){

FILE * ifp,* ofp;

int a;

ifp = fopen (mv,rb);

ofp = fopen(" m"," wt");

a = fgetc(ifp);

if(a == EOF){

fclose(ifp);

}

fputc(a,ofp) );

if(a == EOF){

fclose(ofp);

}

}


因为我不知道文件会有多长时间我无法确切地说

我应该读多少字节所以fread / fwrite是我决定用

fgetc / fputc。我的代码符合标准吗?还有人可以告诉我什么

fputc的第一个int参数是什么?我的参考资料,我看看

不说。但我认为我用得对。我猜到了一个炭盒的容器。


比尔

解决方案



" Bill Cunningham" < no **** @ nspam.comwrote in message

news:V1aMj.3202


Ho5.2125@trnddc01 ...
< blockquote class =post_quotes>
我今天开始在算术运算符上阅读

turtorials之后开始考虑一些文件练习并让我自己迷惑并决定

要做到这一点。

从linux中取mv命令移动并重命名文件,将其读作

binary并将其写为文本。经过一些编译器编译后,我编译了一下,我认为它确实要我想要它。


#include< stdio.h>


int main(无效){

FILE * ifp,* ofp;

int a;

ifp = fopen (mv,rb);

ofp = fopen(" m"," wt");

a = fgetc(ifp);

if(a == EOF){

fclose(ifp);

}

fputc(a,ofp) );

if(a == EOF){

fclose(ofp);

}

}


因为我不知道文件会有多长时间我无法确切地说

我应该读多少字节所以fread / fwrite是我决定用

fgetc / fputc。我的代码符合标准吗?



不完全。


尝试发表评论,描述它应该做什么。


尝试测试一下就可以看到它了!


-

巴特


< blockquote>

" Bartc" < bc@freeuk.com写信息

新闻:1e **************** @ text.news.virginmedia.com。 ..


不完全。


尝试发表评论,描述它应该做什么。


尝试对它进行测试以确定它是这样的!



就测试它而言,EBCDIC文件是用字符编写的所以

似乎有效。但是当我改变了ofp指针并将fopen的模式更改为wb

时,我得到了同样的东西。所以现在我怀疑我得到了我想要的东西

虽然看起来很有用。


比尔


I began to think about some excercises I could with files after reading
turtorials today on arithmetic operators and confusing myself and decided to
do this.
Take the mv command from linux that moves and renames files read it as
binary and write it as text. After some compiler qipes it compiled and I
believe it did want I wanted it to.

#include <stdio.h>

int main(void) {
FILE *ifp, *ofp;
int a;
ifp=fopen("mv","rb");
ofp=fopen("m","wt");
a=fgetc(ifp);
if (a==EOF) {
fclose(ifp);
}
fputc(a,ofp);
if (a==EOF) {
fclose(ofp);
}
}

Because I didn''t know how long the file would be I couldn''t say exactly
how many bytes I should read so fread/fwrite were out and I decided on
fgetc/fputc. Is my code up to standards? And also can someone tell me what
the first int parameter of fputc is and does? My references that I look at
do not say. But I think I used it right. I guessed a ''container'' for a char.

Bill

解决方案


"Bill Cunningham" <no****@nspam.comwrote in message
news:V1aMj.3202


Ho5.2125@trnddc01...

I began to think about some excercises I could with files after reading
turtorials today on arithmetic operators and confusing myself and decided
to do this.
Take the mv command from linux that moves and renames files read it as
binary and write it as text. After some compiler qipes it compiled and I
believe it did want I wanted it to.

#include <stdio.h>

int main(void) {
FILE *ifp, *ofp;
int a;
ifp=fopen("mv","rb");
ofp=fopen("m","wt");
a=fgetc(ifp);
if (a==EOF) {
fclose(ifp);
}
fputc(a,ofp);
if (a==EOF) {
fclose(ofp);
}
}

Because I didn''t know how long the file would be I couldn''t say exactly
how many bytes I should read so fread/fwrite were out and I decided on
fgetc/fputc. Is my code up to standards?

Not quite.

Try putting in a comment describing what it should do.

Try testing it to see that it does so!

--
Bart



"Bartc" <bc@freeuk.comwrote in message
news:1e****************@text.news.virginmedia.com. ..

Not quite.

Try putting in a comment describing what it should do.

Try testing it to see that it does so!

Well as far as testing it an EBCDIC file was written with characters so
it seems to work. But when I changed the ofp pointer and fopen''s mode to wb
I got the same thing. So now I am doubting that I am getting what I want
though it seemed work.

Bill


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

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