Технический форум
Вернуться   Технический форум > Программирование > Форум программистов > Delphi, Kylix and Pascal


Ответ
 
Опции темы Опции просмотра
Старый 13.05.2017, 13:35   #1 (permalink)
exel
Новичок
 
Регистрация: 13.05.2017
Сообщений: 2
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 10
По умолчанию Pascal. Вывод строк в другой файл

имеется текстовый файл из нескольких строк (скажем, не более 100 символов в строке). организовать вывод строк в другой файл в обратном порядке. Использовать память экономно - в качестве буфера в программе применить строку. ее длина должна быть заведомо меньше длины исходного файла. помогите плиз
exel вне форума   Ответить с цитированием

Старый 13.05.2017, 13:35
Helpmaster
Member
 
Аватар для Helpmaster
 
Регистрация: 08.03.2016
Сообщений: 0

Рекомендую не терять времени, а ознакомиться с похожими топиками

Обработка символов и строк на языке Pascal
Pascal ABC: File23. Дан файл вещественных чисел, создать файл целых чисел
Pascal ABC, записи, нужен вывод отсортированной строки
Можно ли торрент-файл ISO открыть другой программой?
Вывод звука через другой выход

Старый 13.05.2017, 14:12   #2 (permalink)
Vladimir_S
Специалист
 
Регистрация: 27.08.2008
Адрес: Санкт-Петербург
Сообщений: 27,807
Сказал(а) спасибо: 340
Поблагодарили 583 раз(а) в 208 сообщениях
Репутация: 113184
По умолчанию

Цитата:
Сообщение от exel Посмотреть сообщение
имеется текстовый файл из нескольких строк (скажем, не более 100 символов в строке). организовать вывод строк в другой файл в обратном порядке. Использовать память экономно - в качестве буфера в программе применить строку. ее длина должна быть заведомо меньше длины исходного файла. помогите плиз
Легко.
Например, так (имена и адреса файлов поставьте, конечно, свои):
Код:
Var
 f1,f2:Text;
 i,N:byte;
 S:String;

Begin
 Assign(f1,'D:\in.txt');
 Reset(f1);
 Assign(f2,'D:\out.txt');
 Rewrite(f2);
 N:=1;
 Repeat
  Readln(f1,S);
  if Not(EoF(f1)) then Inc(N);
 Until EoF(f1);
 Repeat
  Reset(f1);
  for i:=1 to N do Readln(f1,S);
  Writeln(f2,S);
  Dec(N);
 Until N=0;
 Close(f1);
 Close(f2);
End.
Результат:
файл in.txt:

Friends, Romans, countrymen, lend me your ears;
I come to bury Caesar, not to praise him.
The evil that men do lives after them;
The good is oft interred with their bones;
So let it be with Caesar. The noble Brutus
Hath told you Caesar was ambitious:
If it were so, it was a grievous fault,
And grievously hath Caesar answer'd it.
Here, under leave of Brutus and the rest -
For Brutus is an honourable man;
So are they all, all honourable men -
Come I to speak in Caesar's funeral.
He was my friend, faithful and just to me:
But Brutus says he was ambitious;
And Brutus is an honourable man.
He hath brought many captives home to Rome
Whose ransoms did the general coffers fill:
Did this in Caesar seem ambitious?
When that the poor have cried, Caesar hath wept:
Ambition should be made of sterner stuff:
Yet Brutus says he was ambitious;
And Brutus is an honourable man.
You all did see that on the Lupercal
I thrice presented him a kingly crown,
Which he did thrice refuse: was this ambition?
Yet Brutus says he was ambitious;
And, sure, he is an honourable man.
I speak not to disprove what Brutus spoke,
But here I am to speak what I do know.
You all did love him once, not without cause:
What cause withholds you then, to mourn for him?
O judgment! thou art fled to brutish beasts,
And men have lost their reason. Bear with me;
My heart is in the coffin there with Caesar,
And I must pause till it come back to me.

файл out.txt:

And I must pause till it come back to me.
My heart is in the coffin there with Caesar,
And men have lost their reason. Bear with me;
O judgment! thou art fled to brutish beasts,
What cause withholds you then, to mourn for him?
You all did love him once, not without cause:
But here I am to speak what I do know.
I speak not to disprove what Brutus spoke,
And, sure, he is an honourable man.
Yet Brutus says he was ambitious;
Which he did thrice refuse: was this ambition?
I thrice presented him a kingly crown,
You all did see that on the Lupercal
And Brutus is an honourable man.
Yet Brutus says he was ambitious;
Ambition should be made of sterner stuff:
When that the poor have cried, Caesar hath wept:
Did this in Caesar seem ambitious?
Whose ransoms did the general coffers fill:
He hath brought many captives home to Rome
And Brutus is an honourable man.
But Brutus says he was ambitious;
He was my friend, faithful and just to me:
Come I to speak in Caesar's funeral.
So are they all, all honourable men -
For Brutus is an honourable man;
Here, under leave of Brutus and the rest -
And grievously hath Caesar answer'd it.
If it were so, it was a grievous fault,
Hath told you Caesar was ambitious:
So let it be with Caesar. The noble Brutus
The good is oft interred with their bones;
The evil that men do lives after them;
I come to bury Caesar, not to praise him.
Friends, Romans, countrymen, lend me your ears;
Vladimir_S вне форума   Ответить с цитированием
Старый 13.05.2017, 14:15   #3 (permalink)
exel
Новичок
 
Регистрация: 13.05.2017
Сообщений: 2
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 10
По умолчанию

спасибо огромное!!!
exel вне форума   Ответить с цитированием
Старый 13.05.2017, 14:18   #4 (permalink)
Vladimir_S
Специалист
 
Регистрация: 27.08.2008
Адрес: Санкт-Петербург
Сообщений: 27,807
Сказал(а) спасибо: 340
Поблагодарили 583 раз(а) в 208 сообщениях
Репутация: 113184
По умолчанию

Цитата:
Сообщение от exel Посмотреть сообщение
спасибо огромное!!!
Да не за что. Если что непонятно - спрашивайте.
Vladimir_S вне форума   Ответить с цитированием
Ads

Яндекс

Member
 
Регистрация: 31.10.2006
Сообщений: 40200
Записей в дневнике: 0
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 55070
Ответ


Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Выкл.
HTML код Выкл.
Trackbacks are Вкл.
Pingbacks are Вкл.
Refbacks are Выкл.




Часовой пояс GMT +4, время: 05:53.

Powered by vBulletin® Version 6.2.5.
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.