Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h> //для isalpha
- int main(void){
- char strings[100][100], str[100], buff[100];
- bool fl_scob, fl_isfunc;
- FILE *f;
- int count = 0, i, j, k;
- if((f = fopen("input.txt", "r")) == NULL)
- return 1;
- //Считываем строки из файла
- printf("Входной файл:\n");
- while (fgets (str, sizeof(str), f)){
- printf("%s", str);
- //Поиск закрывающей скобки в строке,
- for(i = 0; i < strlen(str); i++){
- fl_scob = false;
- if(str[i] == ')'){
- for(j = i; j > 0; j--)
- if(str[j] == '('){
- fl_scob = true;
- j--;
- break;
- }
- if(fl_scob == true){
- while((isalpha(str[j]) || str[j] == '_') && j != 0 && fl_scob == true)
- j--;
- // is int func?
- if(str[j] == ' ' && str[j-1] == 't' &&
- str[j-2] == 'n' && str[j-3] == 'i' &&
- (str[j-4] == ';' || str[j-4] == ' ' || j - 4 < 0)){
- j = j - 3;
- fl_isfunc = true;
- }
- //is single func?
- if(str[j] == ' ' && str[j-1] == 'e' &&
- str[j-2] == 'l' && str[j-3] == 'g' &&
- str[j-4] == 'n' && str[j-5] == 'i' &&
- str[j-6] == 's' &&
- (str[j-7] == ';' || str[j-7] == ' ' || j - 7 < 0)){
- j = j - 6;
- fl_isfunc = true;
- }
- //is double func?
- if(str[j] == ' ' && str[j-1] == 'e' &&
- str[j-2] == 'l' && str[j-3] == 'b' &&
- str[j-4] == 'u' && str[j-5] == 'o' &&
- str[j-6] == 'd' &&
- (str[j-7] == ';' || str[j-7] == ' ' || j - 7 < 0)){
- j = j - 6;
- fl_isfunc = true;
- }
- //is void func?
- if(str[j] == ' ' && str[j-1] == 'd' &&
- str[j-2] == 'i' && str[j-3] == 'o' &&
- str[j-4] == 'v' &&
- (str[j-5] == ';' || str[j-5] == ' ' || j - 5 < 0)){
- j = j - 4;
- fl_isfunc = true;
- }
- //Если функция, то отправляем в символьный массив.
- if(fl_isfunc == true){
- for(j, k=0; j <= i; j++, k++)
- buff[k] = str[j];
- strcpy(strings[count++], buff);
- memset(buff, 0, sizeof(buff));
- fl_isfunc = false;
- }
- }
- }
- }
- }
- putchar('\n');
- //Вывод перечня функций.
- printf("Перечень функций:\n");
- for(i = 0; i < count; i++)
- printf("%s\n", strings[i]);
- putchar('\n');
- //Сортировка методом пузырька.
- for(i = 1; i < count; i++)
- for(j = 0; j < count - i; j++)
- if(strcmp(strings[j], strings[j+1]) > 0){
- strcpy(str, strings[j]);
- strcpy(strings[j], strings[j+1]);
- strcpy(strings[j+1], str);
- }
- //Выводим отсортированные функции.
- printf("Выводим отсортированные функции:\n");
- for(i = 0; i < count; i++)
- printf("%s\n", strings[i]);
- //Запись в файл
- f = fopen("output.txt", "w");
- for(i = 0; i < count; i++)
- fprintf(f, "%s\n", strings[i]);
- fclose(f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment