Gremlin92
@Gremlin92
Целеустремленный

Считать файл поблочно?

Вот искомый код
FILE *fp,*fencrypted,*fdecrypted;
	char str[N];
	if ((fp=fopen("message.txt", "r" ))==NULL) {
		//printf("Cannot open file.\n");
		std::cout<<"Cannot open file.\n";
		exit (1);
	}
	
	std::vector<uint64_t> *msg = new std::vector<uint64_t>(),
		*plaintext = new std::vector<uint64_t>();//plain text

	unsigned long long id;
	while(!feof (fp)) {
		for (int i = 0; i<N; i++)
			str[i] = '\0';
		if (fgets(str, N, fp))
		{	
			//printf("%s", str);
			std::cout<<str;
			memcpy(&id, str, N);
			msg->push_back(id);
		}

вот сам файл
Business process, activities that produce a specific service or product for customers
Business process modeling, activity of representing processes of an enterprise in order 
Manufacturing process management, a collection of technologies and methods used to define.
Process architecture, structural design of processes, applies to fields such as computers.
Process costing, a cost allocation procedure of managerial accounting
Process management, ensemble of activities of planning and monitoring the performance of .
Process management (Project Management) , a systematic series of activities directed .
Process-based management, is a management approach that views a business as a collection .
Process industry, a category of material-related industry.

fgets плохо получается считывать(последний нуль-символ мешает), точнее разбить весь текст на массивы по 8 символов еще нужно в конец забить нулями если символов меньше 8
  • Вопрос задан
  • 128 просмотров
Решения вопроса 1
Gremlin92
@Gremlin92 Автор вопроса
Целеустремленный
Поменял код на fgetc вроде работает
char ch;
	int countbyte = 0;
	while ((ch = fgetc(fp)) != -1)
	{
		if (countbyte % 8 == 0 && countbyte!=0)
		{
			countbyte = 0;
			std::cout << str;
			memcpy(&id, str, N);
			msg->push_back(id);
			for (int i = 0; i<N; i++)
				str[i] = '\0';
		}
		str[countbyte] = ch;
		countbyte++;
	}
	memcpy(&id, str, N);
	msg->push_back(id);
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы