1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
void CGlobals::ReadDataFromFile(char * pTemplateName, char * pUserId, std::string * pReadData)
{
FILE * fpFile;
char * pData;
char * pFileName;
string sData;
string sFileName;
long iLen;
long dwLength;
long dwResult;
cout<<" Enter into Read Deta Frome File"<<endl;
if(strcmp(pUserId, "NULL"))
{
pFileName = new char[strlen(pTemplateName) + strlen(pUserId) + 1];
iLen = sprintf(pFileName, "%s_%s",
pTemplateName,
pUserId);
}
else
{
pFileName = new char[strlen(pTemplateName)];
iLen = sprintf(pFileName, "%s", pTemplateName);
}
cout<<" Compare finish into Read Deta Frome File"<<endl;
pFileName[iLen] = '\0';
fpFile = fopen(pFileName,"r");
if(!fpFile)
{
pReadData->assign("NONE");
fpFile = fopen(pFileName,"w");
fclose(fpFile);
delete [] pFileName;
pFileName = NULL;
return;
}
cout<<" file open finish into Read Deta Frome File"<<endl;
if(fseek(fpFile,0,SEEK_END))
{
pReadData->assign("NONE");
delete [] pData;
pData = NULL;
fclose(fpFile);
return;
}
cout<<" file seek finish into Read Deta Frome File"<<endl;
dwLength = (long) ftell(fpFile);
fclose(fpFile);
fpFile = fopen(pFileName,"r");
iLen = (long) dwLength;
pData = new char [iLen + 1];
memset(pData,0,strlen(pData));
dwResult = fread (pData,1,iLen,fpFile);
pData[iLen] = '\0';
cout<<" file read finish into Read Deta Frome File"<<endl;
if(dwResult != dwLength)
{
std::cout<<"File Reading Error"<<endl<<pData<<endl;
pReadData->assign("NONE");
}
else if(!dwResult)
pReadData->assign("NONE");
else
{pReadData->assign(pData);}
cout<<" file close finish into Read Deta Frome File"<<endl;
fclose(fpFile);
cout<<" file close finish into Read Deta Frome File"<<endl;
delete [] pData;
pData = NULL;
delete [] pFileName;
pFileName = NULL;
//delete pReadData;
return;
}
|