Advertisement
Ne-Biolog

Untitled

May 19th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <mm_malloc.h>
  2. #include <stdbool.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6. const int BUFFER_SIZE = 100;
  7.  
  8. typedef struct Singer {
  9. char *name;
  10. char **list_of_albums;
  11. char **list_of_tracks;
  12. char *information_abour_singer;
  13.  
  14. } Singer;
  15.  
  16. bool string_comparison(const char *str_a, const char *str_b) {
  17. int len_a = strlen(str_a);
  18. int len_b = strlen(str_b);
  19. if(len_a != len_b) return false;
  20. for(int i = 0; i < len_a; ++i) {
  21. if(str_a[i] != str_b[i]) return false;
  22. }
  23. return true;
  24. }
  25.  
  26. void read_string(char *name) {
  27. printf("1.IN\n");
  28. char ch = '@';
  29. int curr_len = 0;
  30. char *buffer = (char*)malloc(sizeof(char) * BUFFER_SIZE);
  31. while(true) {
  32. ch = getchar();
  33. if(ch != '\n') {
  34. buffer[curr_len] = ch;
  35. curr_len++;
  36. }
  37. else break;
  38. }
  39. curr_len++;
  40. name = (char*)malloc(sizeof(char) * curr_len);
  41. }
  42.  
  43. void add_singer(int size_of_list_of_singers, Singer *list_of_singers) {
  44. Singer *newSinger = (Singer*)malloc(sizeof(Singer*));
  45. read_string(newSinger->name);
  46.  
  47. printf("%s\n", newSinger->name);
  48. }
  49.  
  50. void print_commands() {
  51. printf("1.Add singer\n");
  52. printf("1.Add singer\n");
  53. printf("1.Add singer\n");
  54. printf("1.Add singer\n");
  55. }
  56.  
  57. void menu() {
  58.  
  59. Singer *list_of_singers = NULL;
  60. int size_of_list_of_singers = 0;
  61.  
  62. bool ok = true;
  63. while(ok) {
  64.  
  65. print_commands();
  66.  
  67. int command;
  68. switch(command) {
  69. case 1:
  70. add_singer(size_of_list_of_singers, list_of_singers);
  71. break;
  72. }
  73. }
  74. }
  75.  
  76. int main()
  77. {
  78.  
  79. freopen("input.txt" , "r" , stdin);
  80. freopen("output.txt" , "w" , stdout);
  81.  
  82. Singer *list_of_singers = NULL;
  83. int size_of_list_of_singers = 0;
  84.  
  85. add_singer(size_of_list_of_singers, list_of_singers);
  86.  
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement