Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "my_string.h"
- struct my_string
- {
- int size;
- int capacity;
- char* data;
- };
- typedef struct my_string My_string;
- int main(int argc, char* argv[])
- {
- MY_STRING arrayOfMyStrings[100];
- for (int i = 0; i < 100; i++)
- {
- arrayOfMyStrings[i] = NULL;//my_string_init_default();
- }
- arrayOfMyStrings[0] = my_string_init_c_string("COPY ME!");
- arrayOfMyStrings[1] = my_string_init_c_string("===========================");
- arrayOfMyStrings[2] = my_string_init_default();
- arrayOfMyStrings[3] = my_string_init_c_string("CO");
- for (int i = 1; i < 100; i++)
- {
- my_string_assignment(&arrayOfMyStrings[i],arrayOfMyStrings[0]);
- }
- for (int i = 0; i < 100; i++)
- {
- my_string_insertion(arrayOfMyStrings[i],stdout);
- printf("\n");
- my_string_destroy(&arrayOfMyStrings[i]);
- }
- return 0;
- }
- void my_string_assignment(Item* pLeft, Item Right)
- {
- my_string* pMy_string = (my_string*)*pLeft;
- my_string* rMy_string = (my_string*)Right;
- if(*pLeft == NULL){
- *pLeft = my_string_init_default();
- }
- else{
- while(!my_string_empty(*pLeft))
- my_string_pop_back(*pLeft);
- }
- my_string_concat(*pLeft, Right);
- //if(pMy_string->data == NULL)
- /* {
- *pLeft = my_string_init_c_string(rMy_string->data);
- }
- else
- {
- pMy_string->size = rMy_string->size;
- if(pMy_string->size < pMy_string->capacity)
- {
- for (int e = 0; e < pMy_string->size; e++)
- {
- pMy_string->data[e] = rMy_string->data[e];
- }
- }
- else
- {
- pMy_string->capacity = pMy_string->size*2;
- free(pMy_string->data);
- pMy_string->data = malloc(sizeof(char)*pMy_string->capacity);
- for(int e = 0; e < pMy_string->capacity-1; e++)
- {
- pMy_string->data[e] = rMy_string->data[e];
- }
- }
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement