Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <locale.h>
- struct list
- {
- char elem;
- list* next;
- list* prev;
- };
- void read(FILE* f, list** p)
- {
- char c = getc(f);
- if (c != '.')
- {
- list* ph = new list;
- *p = ph;
- ph->elem = c;
- ph->next = ph;
- ph->prev = ph;
- c = getc(f);
- while (c != '.')
- {
- ph->next = new list;
- ph->next->prev = ph;
- ph = ph->next;
- ph->elem = c;
- ph->next = *p;
- (*p)->prev = ph;
- c = getc(f);
- }
- }
- }
- int result(list* ph)
- {
- int res = 0;
- list* p = ph;
- do
- {
- if (ph->elem == ph->next->elem)
- res = 1;
- ph = ph->next;
- } while (ph != p && res != 1);
- return res;
- }
- int main()
- {
- int i = 0;
- list* p = NULL;
- FILE* f;
- if (!(fopen_s(&f, "file1.txt", "r")))
- read(f, &p);
- else
- printf_s("Не найден файл");
- i = result(p);
- printf_s("%d", i);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement