.
#include<iostream>
#include<locale> //!!!
#include<iomanip>
#include<math.h>
#include<conio.h>
#include<String.h>
#include<ctype.h>
#include <stdlib.h>
#include<windows.h>
#include <fstream> //
using namespace std;
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
ifstream inf; //
char name[21]; //
char str[81]; //
do // <Esc>
{
cout << " ";
cin >> name;
inf.open(name);
if (!inf) //
{
cout<<" \n";
}
else
{
int k = 0; //
while (!inf.eof()) //
{
inf.getline(str,80);
//
k++; //
cout << str << endl;
if ((k+1) % 23 == 0)
// 23
{
cout<< " ";
_getch(); /* */
}
}
int n; // ,
inf.seekg(0L, ios::beg); //
inf.clear(); //
do
{
cout<<" 1 "<< k << " ";
cin>>n;
}while (n>k || n<1);
for (int i=1; i<=n; i++)
inf.getline(str,80);
cout<<str<<endl; /* */
}
inf.close(); /* , */
} while (_getch()!=27);
return 0;
}
, : n- , (n-1) . , , . . .
4. , , 70
( , ). .
#include<iostream>
#include<iomanip>
|
|
#include<math.h>
#include<conio.h>
#include<String.h>
#include<ctype.h>
#include <stdlib.h>
#include<windows.h>
#include <fstream> //
using namespace std;
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
ifstream inf("test.txt"); //
fstream outf("rez.txt",ios::out);
// ( , )
char str[81]; //
char slovo[71]; // 1 ,
char rez[81]; //
rez[0] = '\0'; //
if (!inf) //
cout<<" \n";
else
{
byte flag = 0; //
cout << " :\n";
while (!inf.eof()) //
{
inf >> slovo; //
cout<<slovo<< ' '; //
if (strlen(rez)+strlen(slovo)+1<=70 && strlen(slovo))
/* 70 */
{
if (flag) strcat(rez," ");
// - ,
strcat(rez,slovo); //
flag = 1; //
}
else //
{
outf << rez << endl; //
*rez = '\0'; //
strcpy(rez,slovo); //
}
} //end while
if (*rez) outf << rez << endl;
// ,
outf.close(); //
cout <<"\n\n \n";
_getch();
outf.open("rez.txt",ios::in);
//
cout << "\n :\n";
while(!outf.eof()) //
{
outf.getline(str,80); //
cout << str << endl; //
}
}
_getch();
return 0;
}
5. , , ( )
#include<iostream>
#include<iomanip>
#include<math.h>
#include<conio.h>
#include<String.h>
#include<ctype.h>
#include<stdlib.h>
#include<windows.h>
#include<fstream> //
using namespace std;
// ,
void Replace (char*& str, char* olds,char *news)
/* , , , , .
( ) */
{
char* rez = new char[2*strlen(str)];
/* ; , 2 , */
unsigned char slovo[31]; // 1
unsigned char *s = reinterpret_cast<unsigned char*>(str), *r = reinterpret_cast<unsigned char*>(rez), *sl; /* , */
|
|
while (*s) //
{
sl = slovo;
// sl
while (*s > 0 && *s <= ' ') *r++ = *s++;
//
while (*s > ' ' && *s < 1<<8) *sl++ = *s++;
//
*sl = '\0'; //
if (strcmp(reinterpret_cast<char*>(slovo), olds))
//
sl = slovo;
// sl
else
sl = reinterpret_cast<unsigned char*>(news);
//
while (*sl) *r++ = *sl++;
//
}
*r = '\0'; //
delete []str; //
str = rez; // str
}
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
ifstream inf("test.txt"); //
fstream outf("rez.txt",ios::out);
char* str = new char[81]; //
if (!inf)
cout<<" \n";
else
{
while (!inf.eof()) //
{
inf.getline(str,80); //
cout<<str<<endl; //
Replace(str, "$$", "???");
//
outf << str << endl; //
}
outf.close(); //
// :
outf.open("rez.txt", ios::in);
cout << "\n :\n";
while(!outf.eof())
{
outf.getline(str,81);
cout<<str<<endl;
}
}
delete str;
_getch();
return 0;
}