Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <locale.h>
- #include <cstring>
- #include <string.h>
- #include <stdbool.h>
- #include <windows.h>
- #include <ctype.h>
- int strSize(char* str)
- {
- int i = 0;
- while(str[i] != '\0')
- i++;
- return i;
- }
- char** FileRead(int &Size, char fileName[])
- {
- char** str = NULL;
- Size = 0;
- FILE* f = fopen(fileName, "r");
- if(f != NULL)
- {
- char buf[1000];
- while(!feof(f))
- {
- if(fscanf(f, "%s ", buf))
- {
- char** copyStr = new char*[Size + 1];
- for(int i = 0; i < Size; i++)
- {
- copyStr[i] = new char[strlen(str[i])];
- strcpy(copyStr[i], str[i]);
- delete[] str[i];
- }
- delete[] str;
- str = new char*[Size + 1];
- for(int i = 0; i < Size; i++)
- {
- str[i] = new char[strlen(copyStr[i])];
- strcpy(str[i], copyStr[i]);
- delete[] copyStr[i];
- }
- delete[] copyStr;
- str[Size] = new char[strlen(buf)];
- strcpy(str[Size], buf);
- Size++;
- printf("%s ", buf);
- }
- }
- }
- else
- {
- printf("Ошибка открытия файла!");
- }
- fclose(f);
- printf("\n");
- return str;
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int Size = 0;
- char** str = NULL;
- bool Menu = true;
- while(Menu)
- {
- printf("****************МЕНЮ*******************\n");
- printf("1. Выбор файла по умолчанию \n");
- printf("2. Выбор файла по желанию пользователя\n");
- printf("3. Обработка текста\n");
- printf("4. Вывод списка слов в алфавитном порядке\n");
- printf("5. Выход\n");
- printf("**************************************\n\n");
- int sel = 0;
- scanf("%d", &sel);
- switch (sel)
- {
- case 1:
- str = FileRead(Size, "test.txt");
- break;
- case 2:
- {
- char fileName[256];
- printf("Введите путь к файлу: ");
- scanf("%s", fileName);
- str = FileRead(Size, fileName);
- break;
- }
- case 3:
- {
- for (int i = 0; i < Size; i++)
- if(strlen(str[i]) >= 3)
- str[i][0] = toupper(str[i][0]);
- char* buf = NULL;
- for(int i = 0; i < Size; i++)
- for(int j = i + 1; j < Size; j++)
- if(strcmp(str[i], str[j]) > 0)
- {
- buf = new char[strlen(str[i])];
- buf = str[i];
- str[i] = str[j];
- str[j] = buf;
- delete[] buf;
- }
- printf("Вывод:\n");
- for(int i = 0; i < Size; i++)
- printf("%s\n", str[i]);
- /*for(int j = 0; j < strlen(str[i]); j++)
- {
- if( strlen(str[i]) >= 3 )
- {
- printf("size:%d\n", Size);
- for (int k = 0; k < Size; k++)
- {
- for(int k = 0; k < strlen(str[k]); k++)
- str[j][k] = toupper(str[j][k]);
- printf("%s ", str[j]);
- }
- }
- printf("\n");
- }*/
- break;
- }
- case 4:
- {
- char* buf = NULL;
- for(int i = 0; i < Size; i++)
- for(int j = i + 1; j < Size; j++)
- if(strcmp(str[i], str[j]) > 0)
- {
- buf = new char[strlen(str[i])];
- buf = str[i];
- str[i] = str[j];
- str[j] = buf;
- delete[] buf;
- }
- for(int i = 0; i < Size; i++)
- printf("%s\n", str[i]);
- break;
- }
- case 5:
- Menu = false;
- break;
- }
- }
- for(int i = 0; i < Size; i++)
- delete[] str[i];
- delete[] str;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement