| Задание таково:
"Написать программу на языке C++ чересстрочного слияния (т.е. первая строка в выходном файле - это первая строка из первого файла, вторая строка в выходном файле - это первая строка из второго файла, третья строка в выходном файле - вторая строка из первого файла и т.д.) двух текстовых файлов с удалением в каждой строке слов после которых стоит любой знак препинания."
вот моя прога
#include <stdio.h>
#include <iostream.h>
#include <ctype.h>
#include <stdlib.h>
char* rez_strok_dubl;
int ch_str_1= 0;
int ch_str_2= 0;
int lenf1;
int lenf2;
void func (char* uk, int* ch_str, char* stroka, int len) {
while ((*uk!=10)&&(*ch_str<len-1)) {
uk++;
(*ch_str)++;
}
if (!ispunct(*(uk-1))) {
do {
uk--;
(*ch_str)--;
}
while (!ispunct(*uk)&&(*uk!=10)&&(uk!=stroka));
if (uk!=stroka) {
uk++;
(* ch_str)++;
}
while ((*uk!= 10)&&(*ch_str<len- 1)) {
*rez_strok_dubl++=*uk++;
(*ch_str)++;
}
*rez_strok_dubl++=*uk++;
}
uk++;
(*ch_str)++;
}
int main(){
FILE *f1, *f2;
if (!(f1= fopen ("D:\\work\\file_1.txt", "rb"))) {
cout<<"file_1_ne_otkrit\n";
system ("PAUSE");
exit (1);
}
if (!(f2= fopen ("D:\\work\\file_2.txt", "rb"))) {
cout<< "file_2_ne_otkrit\n";
system ("PAUSE");
exit (1);
}
fseek (f1, 0, SEEK_END);
lenf1=ftell(f1);
fseek (f2, 0, SEEK_END);
lenf2=ftell(f2);
char* stroka_1= (char*) malloc (lenf1) ;
char* stroka_2= (char*) malloc (lenf2) ;
fseek (f1, 0, SEEK_SET);
fseek (f2, 0, SEEK_SET);
fread (stroka_1, lenf1, 1, f1);
fread (stroka_2, lenf2, 1, f2);
fclose (f1);
fclose (f2);
char* rez_strok= (char*) malloc (lenf1+lenf2) ;
rez_strok_dubl= rez_strok;
while (ch_str_2<lenf2) {
func (&stroka_1[ch_str_1], &ch_str_1, stroka_1, lenf1);
func (&stroka_2[ch_str_2], &ch_str_2, stroka_2, lenf2);
}
FILE* f3;
if (!(f3= fopen ("D:\\work\\B.txt", "wb"))) {
cout<< "file_3_ne_otkrit\n";
system ("PAUSE");
exit (1);
}
int i= 0;
while (&rez_strok [i]!= rez_strok_dubl)
fputc ((unsigned char)rez_strok [i++], f3);
fclose (f3);
return 0;
}
|
file_1.txt
First codex was used for accounting, but
with the development of parchment in the III century BC. e., gradually began to displace the papyri.
This is already happening in the Christian world. The reasons for the adoption of the manuscript as the main type of books
several: it is economical because you can use both sides of the paper, it is easy to hide;
It was convenient and accessible. Perhaps the Christian writers used the original purpose, that they were not
similar to the pagan texts, which are usually written in the form of scrolls.
|
file_2.txt
At the beginning of XIV century in Western Europe appeared woodcutting (it was developed
long before the East). In the matrix of woodcuts depicting Pages
cut from a piece of wood. It can be dipped in ink and
used to make multiple copies of a page. Books, as well as playing
cards and religious pictures, began to produce woodcuts. But the creation of the book was
laborious process, since each page had to do his carving. Besides,
First codex was used for accounting, but
with the development of parchment in the III century BC. e., gradually began to displace the papyri.
This is already happening in the Christian world. The reasons for the adoption of the manuscript as the main type of books
several: it is economical because you can use both sides of the paper, it is easy to hide;
It was convenient and accessible. Perhaps the Christian writers used the original purpose, that they were not
similar to the pagan texts, which are usually written in the form of scrolls.
|
B.txt
but
it was developed
In the matrix of woodcuts depicting Pages
The reasons for the adoption of the manuscript as the main type of books
It can be dipped in ink and
as well as playing
that they were not
But the creation of the book was
which are usually written in the form of scrolls.
but
¦
¦ The reasons for the adoption of the manuscript as the main type of books
¦
¦ that they were not
¦ which are usually written in the form of scrolls.
|
1255089691
Проблемы:
1) У меня не получилось организовать слияние строк... В моём случае в первом файле 6 строк, а во втором - 12 строк... При черезстрочном слиянии получается, что когда в первом файле обработалось 6 строк и во втором файле 6 строк, в первом файле строки закончились, но во втором и еще 6.. И они копируются оставляя перед собой то какой-то символ, то просто пустую строчку...
Как бы сделать, чтобы когда одинаковое кол-во строк в файлах закончилось, и если в каком-то файле еще остались строки, то чтобы они просто скопировались в исходный файл (без пропусков строки и всяких посторонних символов)??
2) В моем варианте при встрече знака препинания удаляются все предшествующие ему слова...
Как бы сделать, чтобы удалялось только то слово после которого стоит знак препинания??
Например, чтобы получилось вот так (это вторая строка первого файла...)
Код:
with the development of parchment in the III century gradually began to displace the
|
| |