TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: WADE CARPENTER
from: DANIEL LYNES
date: 1997-07-25 15:01:00
subject: Re: Me again.. HEEEELPPPP!! It`s broken!15:01:0107/25/97

 -=> Quoting Wade Carpenter to All <=-
 WC> I've picked it apart from top to bottom and I can't figure out what's
 WC> up..  I have other code, which is almost the exact same, but it works
 WC> all of the time.  I only cannot enter input, as in this one.  That code
 WC> DOESN'T WORK:
 WC> #include 
 WC> void main(void)
 WC> {
 WC> FILE *fp;
 WC> char msg[88];
 WC> char fspec[50];
 WC> fp = fopen("ZS.CFG","wt");
 WC> fwrite(gets(msg),88,1,fp);
 WC> fwrite(gets(fspec),50,1,fp);
As you can clearly see, 'msg' and 'fspec' are never initialized.
Try the following:
#include 
#include 
int main( void )
{
        //
        //      Declare auto variables
        //
        FILE    *fp ;
        char    msg[88] ;
        char    fSpec[50] ;
        //
        //      Initialize the variables
        //
        fp=NULL ;
        memset( msg, 0, 88 ) ;
        memset( fSpec, 0, 50 ) ;
        fp=fopen( "ZS.CFG", "wt" ) ;            // Open the file
        //
        //      Get input from user, and output to file
        //
        fwrite( gets( msg ), 88, 1, fp ) ;
        fwrite( gets( fspec ), 50, 1, fp ) ;
        fclose( fp ) ;                          // Close the file
        return 0 ;
}
 WC> WORKS:
 WC> char msg[88] = "None";
 WC> char fspec[50] = "None";
As you can see...in the working version, you had initialized your msg[] and 
fspec[] variables in the working version.  The non-working version was not
only not initialized, but it did not contain any null bytes at the end of the
string.  When the user presses '' to end the gets() call, a null byte is
not appended to the result, because the null byte was never entered; only the
newline.
ttfn.
 
... Win95, the good enough release version!
--- Blue Wave v2.12 OS/2 [NR]
---------------
* Origin: The Eclectic Lab (1:153/831)

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™.