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 towrite to and as argument 2 takes num as a number of zeros to write aargument 1. A file of zeros. This is how far I have got. Why would I want afile of zeros? To mount to a loopback device. #include <stdio.h>#include <stdlib.h> intmain (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 amnot 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 filename to write to and as argument 2 takes num as a number of zeros towrite a argument 1. A file of zeros. This is how far I have got. Whywould 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>intmain (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 heresomewhere. 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 messagenews: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>intmain (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 orare 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 heresomewhere. 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 fputworked) 我可以得到那个部分。我想。 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 messagenews: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 fputworked) > 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 这篇关于功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 12:26