Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Курсовик3
.CPP#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
FILE *mfclose(FILE *fl)
{
fclose(fl);
return 0;
};
int main(void)
{
FILE *fl1=NULL,*fl2=NULL;
char *name,buf1,buf2,*name1;
for(char r='y';r=='y';)
{
clrscr();
while(fl1==NULL)
{
cout << "Enter name of source file: \n >";
gets(name);
if((fl1=fopen(name,"r"))==NULL)
{
perror("While file was opening, there were some errors");
cout<<"\n Restart program (y/n) \n >";
cin>>r;
if(r=='n') return 0;
};
};
cout<<"\n\n***Sourse file :: "<<name<<"***\n\n";
buf1=' ';
while(buf1!=EOF)
{
buf1=getc(fl1);
cout<<buf1;
};
cout<<"\n>>EOF\n\nEnter char for replacing \n >";
cin >> buf2;
fl1=mfclose(fl1);
fl1=fopen(name,"r");
buf1=' ';
cout<<"\n>>EOF\n\n***Modified text***\n\n";
while(buf1!=EOF)
{
if(buf2!=(buf1=getc(fl1)))
cout << buf1;
else
cout<<"\n";
};
fl1=mfclose(fl1);
fl2=mfclose(fl2);
cout<<"\n>>EOF\n\n***Save this modified text? (y/n) \n >";
cin>>r;
buf1=' ';
if(r=='y')
{
while(fl2==NULL&&r=='y')
{
cout<<"Enter name of new file to save modified text: \n >";
gets(name1);
if((fl2=fopen(name1,"w"))==NULL)
{
perror("While file was rewriting, there were some errors");
cout<<"\n Repeat enter file name (y/n) \n >";
cin>>r;
};
};
buf1=' ';
if(r=='y')
{
fl1=fopen(name,"r");
cout<<"\n\n***Saved file :: "<<name1<<"***\n\n";
while(buf1!=EOF)
{
if(buf2!=(buf1=getc(fl1)))
{
cout<<buf1;
putc(buf1,fl2);
}
else
{
cout<<"\n";
putc('\n',fl2);
}
};
fl1=mfclose(fl1);
fl2=mfclose(fl2);
};
};
cout<<"\n>>EOF \n\nRepeat start of program (y/n) \n >";
cin>>r;
if(r!='y') return 0;
};
return 0;
};
Соседние файлы в предмете Программирование