TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: WADE CARPENTER
from: ROGER SCUDDER
date: 1997-07-26 14:20:00
subject: Re: Me again.. HEEEELPPPP!! It`s broken!14:20:3107/26/97

/*
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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.