bsuir.info
БГУИР: Дистанционное и заочное обучение
(файловый архив)
Вход (быстрый)
Регистрация
Категории каталога
Другое [157]
АВС [6]
КПиЯП [80]
ОАиП [305]
ОКТ [79]
СиСПО [8]
Форма входа
Логин:
Пароль:
Поиск
Статистика

Онлайн всего: 1
Гостей: 1
Пользователей: 0
Файловый архив
Файлы » ПОИТ » КПиЯП

Контрольная работа №1 В5 files
Подробности о скачивании 02.02.2010, 12:09
#include "stdafx.h"
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <direct.h>
#include <wchar.h>
#include <time.h>
#include <iostream>
#include <cstdlib>
using namespace std;

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;
}

Категория: КПиЯП | Добавил: CTARIK
Просмотров: 960 | Загрузок: 10
Всего комментариев: 0
Добавлять комментарии могут только зарегистрированные пользователи.
[ Регистрация | Вход ]