第28月第3天 c语言读写文件

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] = '';
    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

2.nsstring char *

然后再NSString内搜索:const char ,找到两个:1.[string UTF8String]  2.[string cStringUsingEncoding:<#(NSStringEncoding)#>]

https://blog.csdn.net/u012681458/article/details/50378593

原文地址:https://www.cnblogs.com/javastart/p/10213242.html