读书人

putwgetw函数有关问题

发布时间: 2012-02-16 21:30:36 作者: rapoo

putw,getw函数问题

C/C++ code
putw(int i,FLIE *fp){char *s;s=&i;putc(s[0],fp);putc(s[1],fp);return(i);}getw(FLIE *fp){char *s;int i;s=char *&i;/*不懂,这是什么意思?*/s[0]=getc(fp);s[1]=getc(fp);return(i);}

为什么最后要返回i?

[解决办法]
微软的实现
C/C++ code
int __cdecl _getw (        FILE *str        ){        REG1 FILE *stream;        REG2 int bytecount = sizeof(int);        int word;        char *byteptr = (char *)&word; //注意这句        int retval;        _VALIDATE_RETURN((str != NULL), EINVAL, EOF);        /* Init stream pointer */        stream = str;        _lock_str(stream);        __try {        while (bytecount--)            *byteptr++ = (char)_getc_nolock(stream);        retval = ((feof(stream) || ferror(stream)) ? EOF : word);        }        __finally {            _unlock_str(stream);        }        return(retval);} 

读书人网 >C语言

热点推荐