Re: function



Bill Cunningham wrote:
"Joachim Schmitz" <nospam.jojo@xxxxxxxxxxxxxxxxxx> wrote in message
news:g1rpes$mp7$1@xxxxxxxxxxxx
[OT]
dd if=/dev/zero of=<your file> count=<your size>
[/OT]

Ah. The easy way out :)
Jep 8-) Why reinventing the wheel...

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

Why the termination string character?
It's not just that, it also is the nul character, a byte with all bits
unset.

Do you mean to replace my
line or are you adding one?
Replacing. Do you want zeros in the file or the ascii representation of the
charcter 0? I believe the earlier.

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)

I can get that part. I think.
Yep, left as an excercise to the reader 8-)

Bill
Bye, Jojo


.



Relevant Pages

  • Re: function
    ... main (int argc, char *argv) ... puts ("usage error"); ... exit; ...
    (comp.lang.c)
  • argc issue
    ... int main (int argc, char **argv) ... exit; ... I contais an explotable heap overflow. ...
    (Vuln-Dev)
  • Re: Maintaining multivariable state (newbie question)
    ... extended with various options, and I've ended up making each function taking (..., int argc, char *argv) and then each function would parse it. ... argc, char *argv), but for some reason I needed to change some of the things temporarily, and restore them, so I've ended up doing something like a stack for each global variable. ... And when I started reading lisp I understand the wisdom behind special variables, and all my wasted hours behind emulating what's already have been done. ... That plus the multiple-value returns (Another invention that I needed these days in a C++ code to overcome total rewrite of foreign code portions in a much larger tool - mainly to avoid massive amounts of DLL's to be recompiled). ...
    (comp.lang.lisp)
  • Re: The contents of the file is not read..
    ... int main(int argc, char *argv) ... Buffer overflow protection. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: Newbee needs once more again help with passing arrays out of a function
    ... int argc, char *argv) ... it's best to copy and paste a compilable program ... give them the starting address of some region in memory. ...
    (comp.lang.c)