I am trying to unzip a .zip file, at a specified location. The user inputs the name of the file to be unzipped like "D:\\folder\\sample.zip". I am making use of zip headers and .cpp files from this link https://www.codeproject.com/articles/7530/zip-utils-clean-elegant-simple-c-win
Now below is my code
int main()
{
char filename[100];
HZIP hz; DWORD writ;
printf("Enter filename: \n");
gets(filename);
TCHAR *name = (TCHAR *) filename;
hz = OpenZip(name,0);
SetUnzipBaseDir(hz,_T("D:\\unzipped\\"));
ZIPENTRY ze;
GetZipItem(hz,-1,&ze);
int numitems=ze.index;
for (int zi=0; zi<numitems; zi++)
{
GetZipItem(hz,zi,&ze);
UnzipItem(hz,zi,ze.name);
}
CloseZip(hz);
printf("Unzipped\n");
return 0;
}
I need the filename to be taken as input from the user, for which I had to typecast it by using this statement
TCHAR *name = (TCHAR *) filename;
But this is the statement that is causing problems now. When I debugged the program and added watch to the variable 'name', I saw that after typecasting, it stored some Chinese letters, instead of the path of the zip file
Previously the code worked fine when instead of taking input from user, I hardcoded the path and file name as mentioned below
hz = OpenZip(_T("D:\\folder\\sample.zip"),0);
Any ideas what am I doing wrong?