Guest User

Untitled

a guest
Nov 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. typedef char song[51];
  6. int i=1;
  7.  
  8.  
  9. typedef struct{
  10. int num;
  11. song name;
  12. song artist;
  13. song genre;
  14. song album;
  15. int rating;
  16. char remarks[200];
  17. }SONG;
  18.  
  19. SONG title[100];
  20.  
  21.  
  22. int add(){
  23.  
  24. FILE *fp;
  25.  
  26. fp = fopen("data.dat", "a");
  27. if(fp==NULL){printf("cant open.");}
  28. fprintf(fp, "WELCOME!");
  29. fclose(fp);
  30.  
  31.  
  32. fp = fopen("date.dat", "r");
  33.  
  34. if(fp==NULL){printf("cant open.");}
  35.  
  36. if(fscanf(fp, "%d", &title[i].num)==0){
  37. title[i].num=i;}
  38.  
  39. else{
  40. while(fscanf(fp, "%d", &title[i].num)!=0){
  41. i=i+1;}
  42. }
  43.  
  44. fclose(fp);
  45.  
  46.  
  47. printf("Add song.\n");
  48.  
  49. fp = fopen("data.dat", "a");
  50.  
  51. printf("Title: ");
  52. fgets(title[i].name, 50, stdin);
  53. fprintf(fp,"%s", title[i].name);
  54.  
  55. printf("Artist/Composer: ");
  56. fgets(title[i].artist, 50, stdin);
  57. fprintf(fp,"%s", title[i].artist);
  58.  
  59. printf("Genre (Art, Popular, Traditional) : ");
  60. fgets(title[i].genre, 50, stdin);
  61. fprintf(fp,"%s", title[i].genre);
  62.  
  63. printf("Album: ");
  64. fgets(title[i].album, 50, stdin);
  65. fprintf(fp,"%s", title[i].album);
  66.  
  67. printf("Rating: ");
  68. scanf("%d", &title[i].rating);
  69. getchar();
  70. fprintf(fp,"%d", title[i].rating);
  71.  
  72. printf("Remarks: ");
  73. fgets(title[i].album, 199, stdin);
  74. fprintf(fp,"%s", title[i].remarks);
  75.  
  76.  
  77. fclose(fp);
  78.  
  79. printf("\n\n");
  80.  
  81. return main();
  82. }
  83.  
  84. int display(){
  85. FILE *fp;
  86.  
  87. fp = fopen("data.dat", "r");
  88.  
  89. if(fp==NULL){printf("cant open.");}
  90.  
  91. while(fscanf(fp, "%d", &title[i].num)!=0){
  92. i=i+1;
  93.  
  94. printf("\n");
  95.  
  96. fscanf(fp, "%s", &title[i].name);
  97. printf("%s", title[i].name);
  98. }
  99.  
  100. fclose(fp);
  101. printf("\n\n");
  102. return main();
  103. }
  104.  
  105.  
  106. int main() {
  107. int op;
  108. printf("What do you want to do?\n\n");
  109. printf(" 1. Add a song.\n");
  110. printf(" 2. Update a song.\n");
  111. printf(" 3. List songs.\n");
  112. printf(" 4. Remove duplicate songs.\n");
  113. printf(" 5. Exit.\n\n");
  114. printf("Enter the number corresponding to the operation: ");
  115. scanf("%d", &op);
  116. getchar();
  117.  
  118. if(op==1){
  119. add();}
  120.  
  121. if(op==3){
  122. display();}
  123.  
  124. if(op==5){
  125. return 0;}
  126.  
  127. return 0;
  128. }
Add Comment
Please, Sign In to add comment