I corrected my decision. Here's what happened:
#include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <string.h> unsigned maxlength (FILE* file, char *x); void correction (char *x, unsigned size, unsigned max); void search (FILE* file, char t[20], char *x, unsigned size); void searchwo(FILE* file, char t[20], char *x, unsigned size); int main() { FILE *myfile; char *text, word[20]; unsigned k, size, max, i, j; while (k != 3) { printf("Please, select action: \n 1) Correction \n 2) Search \n 3) Exit \n"); scanf("%d", &k); switch (k) { case 1: myfile = fopen ("input.txt", "r"); fseek(myfile, 0, SEEK_END); size = ftell(myfile); rewind(myfile); text=(char*) malloc(size); max=maxlength(myfile, text); fclose(myfile); myfile = fopen ("output.txt", "w"); correction(text, size, max); for (i=0; i<size; ++i) fputc(text[i], myfile); fclose(myfile); free(text); break; case 2: myfile = fopen ("output.txt", "r"); fseek(myfile, 0, SEEK_END); size = ftell(myfile); rewind(myfile); text=(char*) malloc(size); printf("Enter a word... \n"); scanf("%s", word); printf("1) With register \n2) W\\o register \n"); scanf("%d", &j); switch (j) { case 1: search(myfile, word, text, size); break; case 2: searchwo(myfile, word, text, size); } free(text); fclose(myfile); break; default: printf("Press any key... \n"); } } return 0; } unsigned maxlength (FILE* file, char *x) { unsigned i=0, k=0, max=0; while ((x[i] = fgetc(file)) != EOF) { if ((x[i] != ' ') && (x[i] != '\n')) ++k; else k=0; if (k>max) max=k; ++i; } return max; } void correction (char *x, unsigned size, unsigned max) { unsigned k=0, i=0; if ((x[i]<123) && (x[i]>96)) printf("%c", x[0]=x[0]-32); else printf("%c", x[0]); for (i=1; i<size; ++i) { ++k; if (x[i-4]!='.' && x[i-2]=='.' && ((x[i-1]==' ') || (x[i-1]=='\n')) && (x[i]<123) && (x[i]>96)) printf("%c", x[i]=x[i]-32); else if ((x[i]==' ') && (k>(120-max))) { printf("\n"); k=0; } else printf("%c", x[i]); } printf("\n"); } void search (FILE* file, char t[20], char *x, unsigned size) { unsigned a=0, k=0, max=0, i=0, j=0; max=strlen(t); printf("dlina = %d \n", max); for (i=0; i<size; ++i) x[i]=fgetc(file); for (i=0; i<size; ++i){ if (((x[i] != ' ') && (x[i] != ',') && (x[i] != '.') && (x[i] != '\n') && (x[i] != EOF)) && ((x[i+1]==' ') || (x[i+1]=='.') || (x[i+1]=='\n') || (x[i+1]==EOF) || (x[i+1]==','))) { ++j; } if (t[k]==x[i]) ++k; if (k==max && ((i-max)==-1 || x[i-max]==' ') && (x[i+1]==',' || x[i+1]==' ' || x[i+1]=='.')) { printf("%d ", j); ++a; k=0; } if (((x[i] != ' ') && (x[i] != ',') && (x[i] != '.') && (x[i] != '\n') && (x[i] != EOF)) && ((x[i+1]==' ') || (x[i+1]=='.') || (x[i+1]=='\n') || (x[i+1]==EOF) || (x[i+1]==','))) k=0; } if (a==0) printf("Not found"); printf("\n"); } void searchwo(FILE* file, char t[20], char *x, unsigned size) { unsigned a=0, k=0, max=0, i=0, j=0; max=strlen(t); printf("dlina = %d \n", max); for (i=0; i<size; ++i) x[i]=fgetc(file); for (i=0; i<size; ++i){ if (((x[i] != ' ') && (x[i] != ',') && (x[i] != '.') && (x[i] != '\n') && (x[i] != EOF)) && ((x[i+1]==' ') || (x[i+1]=='.') || (x[i+1]=='\n') || (x[i+1]==EOF) || (x[i+1]==','))) { ++j; } if (t[k]==x[i] || t[k]==x[i]-32 || t[k]==x[i]+32) ++k; if (k==max && ((i-max)==-1 || x[i-max]==' ') && (x[i+1]==',' || x[i+1]==' ' || x[i+1]=='.')) { printf("%d ", j); ++a; k=0; } if (((x[i] != ' ') && (x[i] != ',') && (x[i] != '.') && (x[i] != '\n') && (x[i] != EOF)) && ((x[i+1]==' ') || (x[i+1]=='.') || (x[i+1]=='\n') || (x[i+1]==EOF) || (x[i+1]==','))) k=0; } if (a==0) printf("Not found"); printf("\n"); }