功能 [英] function

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

问题描述

我正在尝试编写一个实用程序,它将一个文件名作为参数1来写入

写入,并且作为参数2将num作为一个零来写一个

参数1.零文件。这是我有多远。为什么我要一个零的

文件?安装到环回设备。


#include< stdio.h>

#include< stdlib.h>

int

main(int argc,char * argv [])

{

if(argc!= 3)

{

put(使用错误);

退出(EXIT_FAILURE);

}

char a =''0'';

int b,num;

FILE * fp;

num = atoi (argv [2]);

fp = fopen(argv [1]," wb");


我想我需要一个for循环涉及到某处。我是

不知道放在身上的是什么。


比尔

I am trying to write a utility that takes as argument 1 a file name to
write to and as argument 2 takes num as a number of zeros to write a
argument 1. A file of zeros. This is how far I have got. Why would I want a
file of zeros? To mount to a loopback device.

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

int
main (int argc, char *argv[])
{
if (argc != 3)
{
puts ("usage error");
exit (EXIT_FAILURE);
}
char a = ''0'';
int b, num;
FILE *fp;
num = atoi (argv[2]);
fp = fopen (argv[1], "wb");

I am thinking that I would need a for loop involved here somewhere. I am
not sure what to put in the body.

Bill

推荐答案

Bill Cunningham写道:
Bill Cunningham wrote:

我正在尝试编写一个实用程序,将一个文件作为参数1

写入的名称和因为参数2将num作为零的数量来表示

写一个参数1.一个零的文件。这是我有多远。为什么

我想要一个零文件?安装到环回设备。
I am trying to write a utility that takes as argument 1 a file
name to write to and as argument 2 takes num as a number of zeros to
write a argument 1. A file of zeros. This is how far I have got. Why
would I want a file of zeros? To mount to a loopback device.



[OT]

dd if = / dev / zero of =< your filecount =< your size>

[/ OT]

[OT]
dd if=/dev/zero of=<your filecount=<your size>
[/OT]


#include< stdio.h>

#include< stdlib.h>


int

main(int argc,char * argv [])

{

if(argc != 3)

{

put(使用错误);

退出(EXIT_FAILURE);

}

char a =''0'';
#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char *argv[])
{
if (argc != 3)
{
puts ("usage error");
exit (EXIT_FAILURE);
}
char a = ''0'';



char a =''\ 0'';

char a = ''\0'';


int b,num;

FILE * fp;

num = atoi(argv [2]);

fp = fopen(argv [1]," wb") ;


我在想这里需要一个for循环

。我不知道该放入体内。
int b, num;
FILE *fp;
num = atoi (argv[2]);
fp = fopen (argv[1], "wb");

I am thinking that I would need a for loop involved here
somewhere. I am not sure what to put in the body.



while(num--)

fputc(a,fp);

fclose(fp);

返回0;

}


仍然需要一些错误检查(num> = 0,fp!= NULL,fclose和fput工作)

while (num--)
fputc(a, fp);
fclose(fp);
return 0;
}

Still needs some error checking (num>=0, fp != NULL, fclose and fput worked)


Bill
Bill



再见,Jojo

Bye, Jojo




" Joachim Schmitz" < no ********* @ schmitz-digital.dewrote in message

news:g1 ********** @ online.de ...

"Joachim Schmitz" <no*********@schmitz-digital.dewrote in message
news:g1**********@online.de...

[OT]

dd if = / dev / zero of =< your filecount =< your size>

[/ OT]
[OT]
dd if=/dev/zero of=<your filecount=<your size>
[/OT]



啊。简单的方法:)

Ah. The easy way out :)


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

主要(int argc,char * argv [])
{
if(argc!= 3)
{
puts(使用错误);
退出(EXIT_FAILURE);
}
char a =''0'';
>#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char *argv[])
{
if (argc != 3)
{
puts ("usage error");
exit (EXIT_FAILURE);
}
char a = ''0'';



char a =''\''';

char a = ''\0'';



为什么终止字符串字符?你的意思是更换我的线路吗?

你要加一个吗?

Why the termination string character? Do you mean to replace my line or
are you adding one?


> int b,num;
FILE * fp;
num = atoi(argv [2]);
fp = fopen(argv [1]," wb");

我在想,我需要在这里涉及到一个for循环
。我不知道该放入体内。
> int b, num;
FILE *fp;
num = atoi (argv[2]);
fp = fopen (argv[1], "wb");

I am thinking that I would need a for loop involved here
somewhere. I am not sure what to put in the body.



while(num--)

fputc(a,fp);

fclose(fp);

返回0;

}


仍然需要一些错误检查(num> = 0,fp!= NULL,fclose和fput

工作)


while (num--)
fputc(a, fp);
fclose(fp);
return 0;
}

Still needs some error checking (num>=0, fp != NULL, fclose and fput
worked)



我可以得到那个部分。我想。

I can get that part. I think.


> Bill
>Bill



再见,Jojo

Bye, Jojo





" Joachim Schmitz" < no ********* @ schmitz-digital.dewrote in message

news:g1 ********** @ online.de ...


[snip]

"Joachim Schmitz" <no*********@schmitz-digital.dewrote in message
news:g1**********@online.de...

[snip]

while(num--)fputc(a,fp);

fclose(fp);

返回0;

}


仍需要一些错误检查(num> = 0,fp! = NULL,fclose和fput

工作)
while (num--) fputc(a, fp);
fclose(fp);
return 0;
}

Still needs some error checking (num>=0, fp != NULL, fclose and fput
worked)

> Bill
>Bill



再见,Jojo

Bye, Jojo



虽然(num--)这是什么?这和我在这里想的一样。


int c;

for(c = 1; c< num; c ++)


Bill

While(num--) What''s that? Is that the same as what I was thinking here.

int c;
for(c=1;c<num;c++)

Bill


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

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