From ac8d1be38c08aab0dd302e3c2228bba22c06e206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nut=CC=A6iu?= Date: Fri, 5 Aug 2016 22:49:07 +0300 Subject: [PATCH] Adding extra folder --- exam_problem2.c => extra/exam_problem2.c | 0 extra/linked.c | 45 ++++++++++++ extra/numbers.txt | Bin 0 -> 800 bytes extra/strings.c | 87 +++++++++++++++++++++++ lab06/l6_2.c | 2 +- 5 files changed, 133 insertions(+), 1 deletion(-) rename exam_problem2.c => extra/exam_problem2.c (100%) create mode 100644 extra/linked.c create mode 100644 extra/numbers.txt create mode 100644 extra/strings.c 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 0000000000000000000000000000000000000000..87a43341bea354fb44182aba9db274cedb7000dd GIT binary patch literal 800 zcmXX^dq|UU6pe}uF)H!e*zcJKEt_Em1E`1^4eUiPu_y1=GV-I5D~DY*gZau>Gqy5Yo8 zUOrB&Z_%o%vMV8HYeR)fEaCP3H1@Rpm>-&~fZ)IB?!~?ejLeoE>o8PcMOjUf^OFPL z2iU@!i#^AI!=A36ksBOfucsRO%fV^H=*yvW*A@o;u_MY6G~8co$6EVDT6>}$4Rz1f zwanV^C9OTo{>nx;H8z}0a;iUTY}h+ykTt7q;Af{M+mIgD+H+#m3g36visFq{+N-sK zueZ)vz^<$DZ^VmQ_N6Cy7ZXozrhS07iycCbc!+~`{6#nrH>>u zg)+qZ63sP8i+m-*iVsD@?e+&e8gsa3v(#yRpLvE@!4# zg2bGUufty$Ff%`-9}hC1I(WI@fBqEsn0G->yq@dvE0QVb(W6AxoIKW5Ogv(XY3{m6 ze(Vr&Rl$t$7s2J|yrV;)^>J@~mJSIq>;mX8-2eOFhX-2Hbwq;>ks +#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;