Re: function
- From: "Joachim Schmitz" <nospam.jojo@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 31 May 2008 17:04:17 +0200
Bill Cunningham wrote:
I am trying to write a utility that takes as argument 1 a file[OT]
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.
dd if=/dev/zero of=<your file> count=<your size>
[/OT]
#include <stdio.h>char a = '\0';
#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.
while (num--)
fputc(a, fp);
fclose(fp);
return 0;
}
Still needs some error checking (num>=0, fp != NULL, fclose and fput worked)
BillBye, Jojo
.
- Follow-Ups:
- Re: function
- From: Bill Cunningham
- Re: function
- From: Bill Cunningham
- Re: function
- References:
- function
- From: Bill Cunningham
- function
- Prev by Date: Re: malloc()/realloc() - have I got this right?
- Next by Date: Re: function
- Previous by thread: function
- Next by thread: Re: function
- Index(es):
Relevant Pages
|