Всем большой пасиб, я уже написал программу сам Кому интересно вот код:
Код | #include <iostream.h> #include <conio.h> #include <stdio.h> #include <string.h> #include <stdlib.h>
#define dataEr printf("\t\t\t\t!!!ERROR!!! \n\n\t\tFILE IS EMPTY or no match symbolyc information!\n\n") #define FileEr printf("\t\t\t\t!!!ERROR!!! \n\n\t\tNo such fiLe or DirEctOry\n\n") #define QUIT printf("\nDo you want to close this program?(y/n)\t"); if( getche()=='y' ) {printf("\n");exit(0);}
long filesize(char*s); int EnterText(char*a,char *s); void OutText(char *p); void ChangeText(char*a);
int main() { while(1) { system("cls"); long a=filesize("C:\\f.dat"); char *text=new char[a]; if(EnterText(text,"C:\\f.dat")!=0) { OutText(text); getch(); system("cls"); ChangeText(text); delete [](text); QUIT; } else exit(0); } getch(); return 0; }
long filesize(char*s) { FILE*stream; long k=0; if((stream=fopen(s,"r"))!=NULL) { while(!feof(stream)) { fgetc(stream); k++; } return k; } else { FileEr; return 0; } }
int EnterText(char *a, char *s) { FILE*f; long k; if((f=fopen(s,"r"))!=NULL) { if((k=(filesize(s)))==0) dataEr; fseek(f,0L,SEEK_SET); for(int i=0;!feof(f);i++) { a[i]=fgetc(f); } a[k-1]='\0';
fclose(f); } else { FileEr; exit(0); } return 1; }
void OutText(char *p) { printf("%s ",p); }
void ChangeText(char *a) { char *delimiters=" ~`!@#$%^&*()_-+=|\\ /,<.>\?\"\';:[]{}¹\t\n\0"; char *str=new char [strlen(a)+1]; char *st=new char [strlen(a)+1]; char ch[2]; int k=-1;
str[0]='\0'; st[0]='\0'; ch[1]='\0'; for(int i=0; i<strlen(a); i++) { ch[0]=a[i]; if(strchr(delimiters,ch[0])) { if(k!=-1) { k++; str[k]='\0'; if(strlen(str)%2) { for(int j=(int)strlen(str)/2;j<strlen(str)-1;j++) str[j]=str[j+1]; str[k-1]=ch[0]; str[k]='\0'; strcat(st,str); } else { str[k]=ch[0]; str[k+1]='\0'; strcat(st,str);
} k=-1; str[0]='\0'; } else { strcat(st,ch); }
} else { k++; str[k]=ch[0]; } } OutText(st); delete[](st); delete[](str); }
|
|