Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <locale>
- #include <windows.h>
- #include <string.h>
- #include <ctype.h>
- #include <conio.h>
- #include "my_Header.h"
- #pragma warning(disable : 4996)
- struct stack_words {
- char inf[100];
- stack_words *next;
- };
- struct add_stack_words {
- char info[100];
- add_stack_words *next_word;
- };
- stack_words *init_stack_words() {
- return NULL;
- }
- add_stack_words *init_add_stack_words() {
- return NULL;
- }
- void push_word(add_stack_words *&s, char *item) {
- add_stack_words *r;
- r = new add_stack_words;
- strcpy(r->info, item);
- r->next_word = s;
- s = r;
- }
- void push(stack_words *&s, char *item) {
- stack_words *r;
- r = new stack_words;
- strcpy(r->inf, item);
- r->next = s;
- s = r;
- }
- char* pop_word(add_stack_words *&s) {
- add_stack_words *r = s;
- char i[100];
- strcpy(i, r->info);
- s = r->next_word;
- delete r;
- return i;
- }
- char* pop(stack_words *&s) {
- stack_words *r = s;
- char i[100];
- strcpy(i, r->inf);
- s = r->next;
- delete r;
- return i;
- }
- char* peek(stack_words *s) {
- return s->inf;
- }
- int empty_stack_words(stack_words *s) {
- return(s) ? 0 : 1;
- }
- int empty_add_stack_words(add_stack_words *s) {
- return(s) ? 0 : 1;
- }
- void task2_print(stack_words* list) {
- printf("---------------------------------------------------------\n");
- int i = 1;
- printf("\n Список слов:");
- while (list) {
- printf("\n %d) %s\n ", i, list->inf);
- list = list->next;
- i++;
- }
- printf("---------------------------------------------------------\n");
- }
- void task2_double(stack_words* list, add_stack_words* word_list) {
- char str[100];
- while (list) {
- strcpy(str, list->inf);
- if (strlen(list->inf) == 1) {
- for (int j = 0; j <= strlen(list->inf); j++) {
- push_word(word_list, str);
- }
- }
- else {
- push_word(word_list, str);
- }
- list = list->next;
- }
- while (word_list) {
- strcpy(str, word_list->info);
- push(list, str);
- word_list = word_list->next_word;
- list = list->next;
- }
- }
- void task2_addnew() {
- FILE *fp;
- FILE *fp1;
- char str[100];
- stack_words *head = init_stack_words();// Инициализация стека
- add_stack_words *begin = init_add_stack_words();
- if ((fp = fopen("read_text.txt", "r")) != NULL) { // Запись элементов из файла в стек
- while (!feof(fp)) {
- fscanf(fp, "%s", &str);
- //printf("\n %d", head);
- push(head, str);
- }
- }
- task2_print(head);
- task2_double(head, begin);
- if ((fp1 = fopen("write_text.txt", "w")) != NULL) { // Печать в файл
- while (!empty_stack_words(head)) {
- strcpy(str,pop(head));
- fprintf(fp1, "%s ", str);
- }
- }
- fcloseall();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement