Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* main.c */
- #include <stdio.h>
- #include <ctype.h>
- #define SIZEB 3
- #define CBLOCKOUTPUT 4
- struct storage {
- char currentCh;
- char hyphen;
- char additionalSymb;
- char lastCh;
- unsigned int hyphenStatus, lastChStatus, additionalSymbStatus, status;
- } symb;
- void resetCh(void);
- void addCh(char *ch);
- int writeGroup(char *ptrSym, char *ptrSym2, char *ptrSym3);
- int main(void) {
- symb.additionalSymbStatus = symb.hyphenStatus = symb.lastChStatus = symb.status = 0;
- FILE *fp;
- if((fp = fopen("referat.txt","r"))==NULL) {
- printf("Can't open file!\n");
- return -1;
- }
- char buffer[SIZEB], ch;
- char *buff = buffer;
- int i;
- do {
- for(i=0;i<SIZEB;++i) {
- ch = getc(fp);
- if(feof(fp)) {
- *(buff+i) = '\0';
- break;
- } else
- *(buff+i) = ch;
- }
- for(i=0;i<SIZEB;++i) {
- if(isalpha(*(buff)) && *(buff+1)=='-' && isalpha(*(buff+2))) {
- printf("%c %c %c\n", *buff, *(buff+1), *(buff+2));
- if(writeGroup(buff, (buff+1), (buff+2))) printf("Error writeGroup call point\n");
- resetCh();
- break;
- }
- if(symb.status) {
- if(symb.lastChStatus) {
- if(*buff == '-') {
- if(isalpha(*(buff+1))) {
- printf("%c %c %c\n",symb.lastCh, *buff, *(buff+1));
- if(writeGroup(&symb.lastCh, buff, (buff+1))) printf("Error writeGroup call point\n");
- resetCh();
- break;
- }
- }
- }
- if(symb.hyphenStatus) {
- if(symb.additionalSymbStatus) {
- if(isalpha(*(buff))) {
- printf("%c %c %c\n", symb.additionalSymb, symb.hyphen, *buff);
- if(writeGroup(&symb.additionalSymb, &symb.hyphen, buff)) printf("Error writeGroup call point\n");
- resetCh();
- break;
- }
- }
- }
- }
- }
- addCh(buff);
- } while(!feof(fp));
- fclose(fp);
- return 0;
- }
- int writeGroup(char *ptrSym, char *ptrSym2, char *ptrSym3) {
- FILE *fpwrite;
- char *ptrArr[3] = {ptrSym, ptrSym2, ptrSym3};
- char str1[5];
- int i;
- for(i=0;i<3;++i) {
- str1[i] = *ptrArr[i];
- }
- str1[3] = '\n';
- str1[4] = '\0';
- if((fpwrite = fopen("output.txt","a"))==NULL) {
- printf("Error open file for writing!\n");
- return -1;
- }
- if(fwrite(str1, sizeof(char), CBLOCKOUTPUT, fpwrite)!=CBLOCKOUTPUT) {
- printf("End write\n");
- fclose(fpwrite);
- return -1;
- }
- fclose(fpwrite);
- return 0;
- }
- void resetCh(void) {
- symb.additionalSymbStatus = symb.hyphenStatus = symb.lastChStatus = symb.status = 0;
- }
- void addCh(char *buff) {
- if(*(buff+(SIZEB-1))=='-') {
- symb.hyphen = *(buff+(SIZEB-1));
- if(isalpha(*(buff+(SIZEB-2)))) {
- symb.additionalSymb = *(buff+((SIZEB-2)));
- symb.additionalSymbStatus = 1;
- symb.hyphenStatus = 1;
- symb.lastChStatus = 0;
- symb.status = 1;
- }
- else
- symb.additionalSymbStatus = 0;
- }
- if(isalpha(*(buff+(SIZEB-1)))) {
- symb.lastCh = *(buff+(SIZEB-1));
- symb.hyphenStatus = 0;
- symb.lastChStatus = 1;
- symb.status = 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement