Advertisement
Guest User

lab4

a guest
Feb 19th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "my_string.h"
  4. int main(int argc, char* argv[])
  5. {
  6. MY_STRING hMy_string = NULL;
  7.  
  8. hMy_string = my_string_init_c_string("james carney");
  9. printf("james carney\n");
  10. //pushes
  11. if(my_string_push_back(hMy_string, ' '))
  12. {
  13. if(my_string_push_back(hMy_string, 'j'))
  14. {
  15. if(my_string_push_back(hMy_string, 'a'))
  16. {
  17. printf("%s\n", my_string_c_str(hMy_string));
  18. printf("size: %d\ncapacity: %d\n", my_string_get_size(hMy_string), my_string_get_capacity(hMy_string));
  19. printf("pushing successful\n");
  20. }
  21. }
  22. }
  23. //pops
  24. if(my_string_pop_back(hMy_string))
  25. {
  26. if(my_string_pop_back(hMy_string))
  27. {
  28. if(my_string_pop_back(hMy_string))
  29. {
  30. printf("%s\n", my_string_c_str(hMy_string));
  31. printf("size: %d\ncapacity: %d\n", my_string_get_size(hMy_string), my_string_get_capacity(hMy_string));
  32. printf("popping successful\n");
  33. }
  34. }
  35. }
  36. printf("the char at index 3, 5, 6 of 'james carney' are: %c, %c, %c\n",
  37. *my_string_at(hMy_string, 3), *my_string_at(hMy_string, 5), *my_string_at(hMy_string,6));
  38.  
  39. MY_STRING other_string = NULL;
  40. other_string = my_string_init_c_string("mclean");
  41. printf("%s\n", my_string_c_str(other_string));
  42. if(my_string_concat(hMy_string, other_string))
  43. {
  44. printf("'james carney' and 'mclean' make %s\n", my_string_c_str(hMy_string));
  45. }
  46. if(!my_string_empty(other_string))
  47. printf("the string is not empty\n");
  48. while(my_string_get_size(other_string) != 0)
  49. {
  50. if(!my_string_pop_back(other_string))
  51. {
  52. printf("cant empty string by popping\n");
  53. break;
  54. }
  55. }
  56. if(my_string_empty(other_string))
  57. printf("the string is empty\n");
  58.  
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement