代码比较简单,请注意代码中标注的 “//出现问题处”将26改为其它值程序显示正常,
#include "stdafx.h"
#define Path "Config.sys"struct Config
{
unsigned long   id;      //机器标识
};int main(int argc, char* argv[])
{
struct Config cfgwrite;
struct Config cfgread;
int numwritten;
FILE *stream; /*写入配置信息*/
cfgwrite.id=26;  //出现问题处
         stream  = fopen( Path, "wb" );
numwritten= fwrite ( &cfgwrite, sizeof( cfgwrite ), 1, stream);
fclose(stream); /*读取配置信息*/
stream  = fopen( Path, "r" );
numwritten= fread ( &cfgread, sizeof( cfgread ), 1, stream);
fclose(stream); /*显示配置信息*/
printf("id is %u",cfgread.id); return 0;
}

解决方案 »

  1.   


    int main(int argc, char* argv[])
    {
    Config cfgwrite;
    Config cfgread;
    int numwritten;
    FILE *stream; /*写入配置信息*/
    cfgwrite.id=26;  //出现问题处
             stream  = fopen( Path, "wb" );
    numwritten= fwrite ( &cfgwrite, sizeof( cfgwrite ), 1, stream);
    fclose(stream); /*读取配置信息*/
    stream  = fopen( Path, "r" );
    numwritten= fread ( &cfgread, sizeof( cfgread ), 1, stream);
    fclose(stream); /*显示配置信息*/
    printf("id is %u",cfgread.id); return 0;
    }
      

  2.   


    /*读取配置信息*/
    stream  = fopen( Path, "r" );
    numwritten= fread ( &cfgread, sizeof( cfgread ), 1, stream);
    fclose(stream);fopen的摸式改成"rb"看看。
      

  3.   

    hanyixin(怡) ( ) 信誉:100 这个正确!~
      

  4.   

    呵呵,多谢各位捧场谢谢 hanyixin(怡) ,问题解决了马上加分