Re: function



Bill Cunningham wrote:
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 file> count=<your size>
[/OT]

#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';

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)

Bill
Bye, Jojo


.



Relevant Pages

  • function
    ... A file of zeros. ... main (int argc, char *argv) ... int b, num; ...
    (comp.lang.c)
  • Re: in_range() macro proposal
    ... this implementation is conforming ... In effect there are two kinds of addresses, those with zeros in ... the low order two bits, and those with at least one of the low ... Incrementing a (char*) is done differently ...
    (comp.std.c)
  • Re: libtommath - Greg Rose - Help on libtommath
    ... product x*y with some number of digits of zeros appended based on char ... *** Dump of q1 ...
    (sci.crypt)
  • Re: in_range() macro proposal
    ... this implementation is conforming ... In effect there are two kinds of addresses, those with zeros in ... Incrementing a (char*) is done differently ... belong to the same family, and then just comparing them numerically. ...
    (comp.std.c)
  • libtommath - Greg Rose - Help on libtommath
    ... In other words - I would expect to get the correct upper digits of the ... product x*y with some number of digits of zeros appended based on char ... incorrect. ...
    (sci.crypt)