#include #include #include int write_file(const char *text, const char *file); int main() { FILE *fin; int i, ch, end = 0, length = 0; const char *end_str = "END", *end_sen = ".!?"; char filename[25] = {0}, *p; if ((fin = fopen("temp.log", "w+")) == NULL) { printf("Error opening file\n"); return 1; } while ((ch = getchar()) != EOF) { if (!strchr(end_str, ch)) { for (i = 0; i < end; i++) fputc(end_str[i], fin); length++; length += end; end = 0; fputc(ch, fin); if (strchr(end_sen, ch)) { fputc('\n', fin); length++; } } else { if (!end && strchr(end_str + 1, ch)) { fputc(ch, fin); length++; } else { if (end_str[end] == ch) { end++; if (end == 3) break; } } } } i = 0; p = (char *) calloc(length + 1, 1); rewind(fin); while ((ch = fgetc(fin)) != EOF) p[i++] = ch; fclose(fin); getchar(); printf("Filename: "); fgets(filename, sizeof(filename), stdin); filename[strcspn(filename, "\n")] = 0x00; if (write_file(p, filename)) { printf("Error\n"); } else { printf("Sucessfull!\n"); } getche(); free(p); return 0; } int write_file(const char *text, const char *file) { FILE *fin; if ((fin = fopen(file, "w")) == NULL) return 1; if (fwrite(text, 1, strlen(text), fin) < strlen(text)) { fclose(fin); return 1; } fclose(fin); return 0; }