Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- typedef struct NEXTELEMENT
- {
- struct NEXTELEMENT *next;
- char character;
- unsigned int line;
- } EDITORLIST;
- typedef struct LISTHEAD
- {
- struct LISTHEAD *next;
- } LISTHEAD;
- void add_element_of_list(EDITORLIST *_my_list, char *_character, unsigned int *_line, unsigned int *_position_in_line)
- {
- /*
- * @_my_list pierwszy element listy
- * @_character znak przekazywany do listy
- * @_line numer lini w ktorej ma znajdowac sie znak
- * @_position_in_line przechowuje wartosc ktory to znak w lini
- * @line_counter zlicza linie w petli
- * @position_counter po osiagnieciu odpowiedniej petli zlicza znaki
- * @new_element tworzy nowy element listy dodawany po @element_finder
- */
- unsigned int line_counter = 1, position_counter = 1;
- EDITORLIST *new_element;
- while (_my_list->next != NULL)
- {
- if (line_counter == _line)
- {
- if (position_counter == _position_in_line)
- {
- new_element = malloc(sizeof(EDITORLIST));
- new_element->character = _character;
- new_element->line = _line;
- new_element->next = NULL;
- _my_list->next = new_element;
- return;
- }
- else
- {
- position_counter++;
- }
- }
- else if (_my_list->next->character == '\n')
- {
- line_counter++;
- }
- _my_list = _my_list->next;
- }
- }
- void delete_element_from_list(EDITORLIST *_my_list, unsigned int *_line, unsigned int *_position_in_line)
- {
- /*
- * @_my_list pierwszy element listy
- * @_line numer lini w ktorej ma znajdowac sie znak
- * @_position_in_line przechowuje wartosc ktory to znak w lini
- * @line_counter zlicza linie w petli
- * @position_counter po osiagnieciu odpowiedniej petli zlicza znaki
- * @del_element wskazuje na element poprzedzajacy ten do usuniecia
- */
- unsigned int line_counter = 1, position_counter = 1;
- while (_my_list->next != NULL)
- {
- if (line_counter == _line)
- {
- if (position_counter == _position_in_line)
- {
- EDITORLIST *del_element;
- del_element = _my_list->next;
- _my_list->next = del_element->next;
- free(del_element);
- return;
- }
- else
- {
- position_counter++;
- }
- }
- else if (_my_list->next->character == '\n')
- {
- line_counter++;
- }
- _my_list = _my_list->next;
- }
- }
- EDITORLIST *my_list;
- int main()
- {
- unsigned int a = 4;
- unsigned int b = 5;
- char c = 'c';
- add_element_of_list(&my_list, &c, &a, &b);
- delete_element_from_list(&my_list, &a, &b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement