diff --git a/exam_problem2.c b/extra/exam_problem2.c similarity index 100% rename from exam_problem2.c rename to extra/exam_problem2.c diff --git a/extra/linked.c b/extra/linked.c new file mode 100644 index 0000000..6db44f6 --- /dev/null +++ b/extra/linked.c @@ -0,0 +1,45 @@ +#include +#include + +typedef struct _list * List; + +struct _list +{ + int data; + List next; +}; + +List init(int data) { + List new = (List) malloc(sizeof(struct _list)); + new->next = NULL; + new->data = data; + return new; +} + +void add(List list, int data) { + // List head = list; + while(list->next != NULL) { + list = list->next; + } + list->next = (List) malloc(sizeof (struct _list)); + list->next->next = NULL; + list->next->data = data; +} + +void print_list(List list) { + while (list) { + printf("%d%c", list->data, list->next == NULL ? '\n' : ' '); + list = list->next; + } +} + +int main(int argc, char const *argv[]) +{ + List l = init(1); + add(l, 2); + add(l, 3); + add(l, 4); + add(l, 5); + print_list(l); + return 0; +} \ No newline at end of file diff --git a/extra/numbers.txt b/extra/numbers.txt new file mode 100644 index 0000000..87a4334 Binary files /dev/null and b/extra/numbers.txt differ diff --git a/extra/strings.c b/extra/strings.c new file mode 100644 index 0000000..85bd237 --- /dev/null +++ b/extra/strings.c @@ -0,0 +1,87 @@ +/* + ============================================================================ + Name : test.c + Author : Denis + Version : + Copyright : Your copyright notice + Description : Hello World in C, Ansi-style + ============================================================================ + */ + +#include +#include + +int len(char const * string) { + int i = 0; + while(*string) { + i++; + string++; + } + return i; +} + +void swap(char * a, char * b) { + int temp = *a; + *a = *b; + *b = temp; +} + + +char const *find_char( char const *source, char const *chars ) { + while (*chars) { + for (char const * i = source; *i; ++i) { + if ( *chars == *i) { + return i; + } + } + ++chars; + } + return NULL; +} + +int del_substr( char *str, char const *substr ) { + int is_in_string = 0; + int substr_len = len(substr); + int length = 0; + int index = 0; + for (int i = 0; str[i]; ++i) { + length = 0; + while ( str[i + length] == substr[length] ) { + ++length; + if( !substr[length] ) { + index = i; + is_in_string = 1; + goto exit_loop; + } + } + } + exit_loop: + if ( is_in_string ) { + int counter; + for (counter = 0; str[index + length + counter]; ++counter) { + str[index + counter] = str[index + length + counter]; + } + str[index + counter] = '\0'; + } + return is_in_string; +} + + +void reverse_string(char * string) { + int size = len(string) - 1; + for (int i = 0; i < size / 2; i++) { + swap(string + i, string + size - i); + } +} + +int main(void) { + char ana[] = "Ana areare mere."; + //reverse_string(ana); + printf("%s", ana); + printf("\n"); + //printf("%s", find_char(ana, "era") ); + printf("\n"); + int x = del_substr(ana, "are"); + printf(" %d %s", x, ana); + return EXIT_SUCCESS; +} diff --git a/lab06/l6_2.c b/lab06/l6_2.c index 8ce2e6f..92d551f 100644 --- a/lab06/l6_2.c +++ b/lab06/l6_2.c @@ -89,7 +89,7 @@ void area_rectangle(struct gshape *gs) { double length = gs->gshape.rectangle.x4 - gs->gshape.rectangle.x1; double width = gs->gshape.rectangle.y4 - gs->gshape.rectangle.x4; printf("AREA OF RECTANGLE #%d IS: %g\n", gs->ID, fabs(length*width) ); -} +} int main() { int i, type;