Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- # define SIZE 500
- int strlen(char * str);
- int isDelimiter(char c);
- void checkRegister(char * buffer);
- void showСorrectText(char * buffer, FILE * result);
- int main() {
- int i = 0;
- char buffer[SIZE];
- FILE * text, *result;
- text = fopen("text.txt", "r");
- result = fopen("newtext.txt", "w");
- if (text == NULL || result == NULL) {
- printf("Error occured!\n");
- system("pause");
- exit(1);
- }
- fgets(buffer, SIZE, text);
- checkRegister(buffer);
- showСorrectText(buffer, result);
- fclose(text);
- fclose(result);
- system("pause");
- return 1;
- }
- int strlen(char * str) {
- int len = 0;
- while (str[len++]);
- return len - 1;
- }
- int isDelimiter(char c) {
- int i;
- char delimiters[] = {
- '.',
- '!',
- '?'
- };
- for (i = 0; i < 3; i++)
- if (c == delimiters[i])
- return 1;
- return 0;
- }
- void checkRegister(char * buffer) {
- for (int j = 0; buffer[j] != '\0'; j++) {
- if (isDelimiter(buffer[j])) {
- if (toupper(buffer[j + 1]))
- buffer[j + 1] = toupper(buffer[j + 1]);
- }
- if (isDelimiter(buffer[j]) && (buffer[j + 1] == ' ')) {
- if (toupper(buffer[j + 2])) {
- buffer[j + 2] = toupper(buffer[j + 2]);
- j += 2;
- }
- }
- else if (tolower(buffer[j]) && !isDelimiter(buffer[j - 1]))
- buffer[j] = tolower(buffer[j]);
- if (toupper(buffer[0]))
- buffer[0] = toupper(buffer[0]);
- }
- }
- void showСorrectText(char * buffer, FILE * result) {
- int j, i;
- char temp[SIZE];
- for (j = 0, i = 0; buffer[j] != '\0';) {
- if (buffer[i] == ' ' && buffer[i + 1] == ' ') {
- temp[j] = ' ';
- i++;
- continue;
- }
- if ((isDelimiter(buffer[i]) || buffer[i] == ',') && (buffer[i + 1] != ' ')) {
- temp[j] = buffer[i];
- temp[j + 1] = ' ';
- j += 2;
- i++;
- continue;
- }
- temp[j] = buffer[i];
- i++;
- j++;
- }
- temp[j] = '\0';
- for (i = 0; temp[i] != '\0'; i++) {
- printf("%c", temp[i]);
- }
- fputs(temp, result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement