第28月第3天 c語言讀寫文件
阿新 • • 發佈:2019-01-03
emc ado urn != || spa new tolower see
1.
int ConfigIniFile::OpenFile( const char* szFileName ) { FILE *fp; size_t nLen; int nRet; CloseFile(); if ( 0 == szFileName ) { return -1; } #if defined(_WIN32) m_szFileName = _strdup( szFileName ); #else m_szFileName = strdup( szFileName );#endif fp = fopen( m_szFileName, "rb" ); if ( 0 == fp ) { return -1; } nRet = fseek( fp, 0L, SEEK_END ); if (nRet != 0) { fclose( fp ); return -1; } nLen = (size_t) ftell( fp ); m_szContent = (char* ) new char[ nLen + 1 ]; m_szShadow= (char* ) new char[ nLen + 1 ]; if ( m_szShadow == 0 || m_szContent == 0 ) { fclose( fp ); return -1; } nRet = fseek( fp, 0L, SEEK_SET ); if ( 0 != nRet ) { fclose( fp ); return -1; } m_nSize = fread( m_szContent, 1, nLen, fp ); m_szContent[m_nSize]= ‘\0‘; memcpy( m_szShadow, m_szContent, m_nSize + 1 ); ToLower( m_szShadow, m_nSize + 1 ); fclose( fp ); m_bOpen = true; return 0; }
http://blog.51cto.com/7666425/1264690
https://github.com/huhu4017/hello-world/blob/c5a345a1bfeedf2a84744d2f3c5da37fc05ad67d/common/ConfigIniFile.cpp
第28月第3天 c語言讀寫文件