C_技巧

  现在越来越感觉到我们做图象算法的,写好通用的c才是王道。记录下些平时的技巧,大家探讨

1. 得到文件长度

long  fgetlength(char *sfile)
{
    if(sfile==NULL || _access(sfile,0)!=0 ) return 0;
    FILE *pf =fopen(sfile,"r+b"); if(pf==NULL) return 0;
    long length = 0;
    fseek(pf,SEEK_END);
    length = ftell(pf);
    fclose(pf);
    return pf;   

 2.  历遍文件 (zz from honker110(honker)

#include
#include
#include
#include
#include
#include

main()
{
    std::string str = "ISAPI Upload Demo";
    struct _finddata_t c_file;    
    long hFile;    
    /*   Find   first   .c   file   in   current   directory   */    
    if((hFile = _findfirst("*.*", &c_file)) == -1L)    
    printf("No files in directory!/n");    
    else    
    {    
        str += c_file.name;
        str += "
";
        /*   Find   the   rest   of   the   .c   files   */    
        while(   _findnext(   hFile,   &c_file   )   ==   0   )    
        {
            str += c_file.name;
            str += "
";
         }    

        _findclose(   hFile   );    
    }    
    str += "";
    printf(str.c_str());
}

你可能感兴趣的:(VC技术文档)