/*
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");
}
The main problem is that fwrite is used for binary writes
and you are specifying text whan you open the file. I also
wouldn't try to nest gets inside of fwrite because it is both
incorrect and not good style.
Ok, you don't want to use fwrite or gets... infact, never use
gets ever again!
*/
#include
#include
#define MAXLEN 260 /* lots of room here will avoid problems */
int main(void)
{
const char *errmsg = "File open failed";
FILE *fp;
char msg[MAXLEN];
char fspec[MAXLEN];
fp = fopen("ZS.CFG","w");
/* ALWAYS test for success after opening a file */
if(NULL == fp)
{
fprintf(stderr,"%s\n", errmsg);
exit(1);
}
fgets(msg, MAXLEN, stdin);
fputs(msg, fp);
fgets(fspec, MAXLEN, stdin);
fputs(fspec, fp);
fclose(fp);
printf("Done!\r\n");
return EXIT_SUCCESS; /* ALWAYS return an int */
}
Roger
--- AdeptXBBS v2.14(WC) (*FREEWare/2*)
---------------
* Origin: The Cereal Port BBS 603-899-3335 199.125.78.133 (1:132/152)
|