代码编译有关问题
代码编译问题
- C/C++ code
#include <stdio.h> #include <windows.h> int nCounter = 0; FILE *fp; bool FilterChar(char *pChar) { for(int i=0;i<31;i++) if(*pChar == "\n\r<>,/?\\{}[]();:\'\" =%^*#!`~+\0&\t"[i]) return true; return false; } bool IsGoodEmail(char *pEmail) { int a = strcspn(pEmail, "@"), b = strcspn(pEmail,"."), c = strlen(pEmail)-1; if(pEmail[0] == '@' || (a+1) == b) return false; if(!IsCharAlpha(pEmail[c])) pEmail[c] = '\0'; if((a < c) && (b > a) && (b < c)) return true; return false; } bool IsValidFile(char *pFile) { int x = 0; int nStrLen = lstrlen(pFile); char *pExt = new char[nStrLen]; ZeroMemory(pExt,nStrLen); bool bRet = false; for(int i = nStrLen;i>0;i--){ if(pFile[i] == '.'){ while(i<nStrLen){ pExt[x] = pFile[i]; x++;i++; } break; } } if(!lstrcmp(pExt,".txt") || !lstrcmp(pExt,".htm") || !lstrcmp(pExt,".html") || !lstrcmp(pExt,".cpp") || !lstrcmp(pExt,".h") || !lstrcmp(pExt,".php")) bRet = true; delete pExt; pExt = NULL; return bRet; } void ScanFile(char *lpszFile) { if(IsValidFile(lpszFile)) SetConsoleTitle(lpszFile); else return; HANDLE hFile = CreateFile(lpszFile,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFile != NULL || hFile != INVALID_HANDLE_VALUE) { DWORD dwFileSize = GetFileSize(hFile,NULL); if(dwFileSize != INVALID_FILE_SIZE) { char *lpszFileBuffer = new char[dwFileSize]; ZeroMemory(lpszFileBuffer,dwFileSize); DWORD dwRet = 0; ReadFile(hFile,lpszFileBuffer,dwFileSize,&dwRet,NULL); char *pEmail = new char[MAX_PATH]; ZeroMemory(pEmail,MAX_PATH); char *pData = lpszFileBuffer; unsigned int c = 0; do{ if(*pData == '@'){ while(!FilterChar(pData)) *pData--; *pData++; while(!FilterChar(pData)){ if(c < MAX_PATH-1){ pEmail[c] = *pData; c++; *pData++; } else break; } if(IsGoodEmail(pEmail)){ printf("%s\n",pEmail); fprintf(fp,"%s\n",pEmail);nCounter++; } ZeroMemory(pEmail,MAX_PATH); c = 0; } }while(*pData++); pData = NULL; delete lpszFileBuffer; CloseHandle(hFile); } CloseHandle(hFile); } } static bool ScanDirectory(char *lpszDirectory,DWORD dwSize) { HANDLE hFind; WIN32_FIND_DATA *fd = new WIN32_FIND_DATA; ZeroMemory(fd,sizeof(WIN32_FIND_DATA)); char * lpszBuffer; DWORD dwNewSize = 0; bool bStatus = true; DWORD dwActualSize = dwSize+3; char * lpszScanDir = new char[dwActualSize]; ZeroMemory(lpszScanDir,dwActualSize); wsprintf(lpszScanDir,"%s\\*",lpszDirectory); hFind = FindFirstFile(lpszScanDir,fd); if(hFind != INVALID_HANDLE_VALUE) { do{ if(fd->cFileName[0] != '.'){ dwNewSize = (dwSize + lstrlen(fd->cFileName) + 3); lpszBuffer = new char[dwNewSize]; ZeroMemory(lpszBuffer,dwNewSize); wsprintf(lpszBuffer,"%s\\%s",lpszDirectory,fd->cFileName); if(!ScanDirectory(lpszBuffer,dwNewSize)) ScanFile(lpszBuffer); delete lpszBuffer; } } while(FindNextFile(hFind,fd)); } else bStatus = false; FindClose(hFind); delete fd,lpszBuffer,lpszScanDir; return bStatus; } int main(int argc,char **argv) { char *lpszScanDir = new char[MAX_PATH]; ZeroMemory(lpszScanDir,MAX_PATH); char *savefile="d:\\邮件.txt";//保存文件目录 fp=fopen(savefile,"a"); SetConsoleTitle("Email Scanner v1.0 - By Smith"); printf("Email scanner v1.0\nBy Smith\n\nEnter directory to scan\nExample \"c:\" (without quotes)\n\n> "); scanf("%s",lpszScanDir); ScanDirectory(lpszScanDir,lstrlen(lpszScanDir)); delete lpszScanDir; SetConsoleTitle("Email Scanner v1.0 - By Smith"); printf("\nTotal emails found: %d ,save in file %s.\nPress escape to exit...",nCounter,savefile); fprintf(fp,"\nTotal emails found: %d\nPress escape to exit...",nCounter); while(!GetAsyncKeyState(VK_ESCAPE)) Sleep(10); fclose(fp); return 0; }