> Ok.. Here's the problem. This code is meant to write
> 138 bytes of information
> to a file, "ZS.CFG" but it writes whatever is entered
> plus garbage, or
> sometimes it make a couple of extra lines, make a 139
> byte file, or sometimes
> it writes the first fwrite plus garbage and not the
> second one. Either way, it
> doesn't work. I am just distraught here. I've picked
> it apart from top to
> bottom and I can't figure out what's up.. I have
> other code, which is almost
> the exact same, but it works all of the time. I only
> cannot enter input, as in
> this one. That code is the second included bit.
> DOESN'T WORK:
> #include
> void main(void)
> {
> FILE *fp;
> char msg[88];
> char fspec[50];
> fp = fopen("ZS.CFG","wt");
> fwrite(gets(msg),88,1,fp);
> fwrite(gets(fspec),50,1,fp);
> fclose(fp);
> printf("Done!\r\n");
> }
First one works differently because you don't clear the arrays, and they
contain garbage when declared. Second one initializes them and fills with
zeros. Try memset(msg, 0, 88) and memset(fspec, 0, 50) just after the
declaration, or even 'char mag[88] = "";', that should solve the problem.
---
---------------
* Origin: A point in the middle of nowhere (2:490/31.3100)
|