int _tmain(int argc, wchar_t * argv[]) { FILE *fstream, *fstreamB, *fstreamC; char ftype[4], ftype2[4]; errno_t err; char buff[2]; char list[255]; int count = 0; char cCurrentPath[255]; char space[] = {' '};
if (!_getcwd(cCurrentPath, sizeof(cCurrentPath))) { return errno; }
cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */
if (argc == 3) { char tmp[4]; char stFileName[255]; wcstombs(stFileName, argv[1],(int)wcslen(argv[1])); wcstombs(tmp, argv[2], 3); stFileName[(int)wcslen(argv[1])] = '\0'; tmp[sizeof(tmp)-1] = '\0';
if (strcmp(tmp, "txt") == 0) { strcpy_s(ftype,sizeof(ftype),"r+t"); strcpy_s(ftype2,sizeof(ftype),"w+t"); } if (strcmp(tmp, "bin") == 0) { strcpy_s(ftype,sizeof(ftype),"r+b"); strcpy_s(ftype2,sizeof(ftype),"w+b"); } string strPath (""); strPath.clear(); strPath = cCurrentPath; strPath.insert(strPath.length(),"\\"); strPath.insert(strPath.length(),stFileName); strPath = strPath.substr(0,strPath.length()); if ((err = fopen_s(&fstream, strPath.c_str(), ftype)) == 0) { int i = 0; bool flag = true; int j = 0; strPath = cCurrentPath; strPath.insert(strPath.length(),"\\inputB.txt"); fopen_s(&fstreamB, strPath.c_str(), ftype2); strPath = cCurrentPath; strPath.insert(strPath.length(),"\\inputC.txt"); fopen_s(&fstreamC, strPath.c_str(), ftype2); while(!feof(fstream)) { fread(buff, sizeof(char), 1, fstream ); buff[sizeof(buff)-1] = '\0';
if (buff[0] >= '0' && buff[0] <= '9') { list[j] = buff[0]; j++; flag = false; }
if ((buff[0] == ' ' || buff[0] == '\n' || buff[0] == '\t' || buff[0] == '\r') && ((int)strlen(list) > 0)) { list[j] = '\0';
__int64 num = _atoi64(list); int len = (int)strlen(list); if (num % 2 == 0) fwrite(list, len+1, 1, fstreamB); else fwrite(list, len+1, 1, fstreamC); j = 0; list[0] = '\0'; flag = true; } }
fclose(fstreamB); fclose(fstreamC); fclose(fstream); } }
return 0; }