Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- typedef char song[51];
- int i=1;
- typedef struct{
- int num;
- song name;
- song artist;
- song genre;
- song album;
- int rating;
- char remarks[200];
- }SONG;
- SONG title[100];
- int add(){
- FILE *fp;
- fp = fopen("data.dat", "a");
- if(fp==NULL){printf("cant open.");}
- fprintf(fp, "WELCOME!");
- fclose(fp);
- fp = fopen("date.dat", "r");
- if(fp==NULL){printf("cant open.");}
- if(fscanf(fp, "%d", &title[i].num)==0){
- title[i].num=i;}
- else{
- while(fscanf(fp, "%d", &title[i].num)!=0){
- i=i+1;}
- }
- fclose(fp);
- printf("Add song.\n");
- fp = fopen("data.dat", "a");
- printf("Title: ");
- fgets(title[i].name, 50, stdin);
- fprintf(fp,"%s", title[i].name);
- printf("Artist/Composer: ");
- fgets(title[i].artist, 50, stdin);
- fprintf(fp,"%s", title[i].artist);
- printf("Genre (Art, Popular, Traditional) : ");
- fgets(title[i].genre, 50, stdin);
- fprintf(fp,"%s", title[i].genre);
- printf("Album: ");
- fgets(title[i].album, 50, stdin);
- fprintf(fp,"%s", title[i].album);
- printf("Rating: ");
- scanf("%d", &title[i].rating);
- getchar();
- fprintf(fp,"%d", title[i].rating);
- printf("Remarks: ");
- fgets(title[i].album, 199, stdin);
- fprintf(fp,"%s", title[i].remarks);
- fclose(fp);
- printf("\n\n");
- return main();
- }
- int display(){
- FILE *fp;
- fp = fopen("data.dat", "r");
- if(fp==NULL){printf("cant open.");}
- while(fscanf(fp, "%d", &title[i].num)!=0){
- i=i+1;
- printf("\n");
- fscanf(fp, "%s", &title[i].name);
- printf("%s", title[i].name);
- }
- fclose(fp);
- printf("\n\n");
- return main();
- }
- int main() {
- int op;
- printf("What do you want to do?\n\n");
- printf(" 1. Add a song.\n");
- printf(" 2. Update a song.\n");
- printf(" 3. List songs.\n");
- printf(" 4. Remove duplicate songs.\n");
- printf(" 5. Exit.\n\n");
- printf("Enter the number corresponding to the operation: ");
- scanf("%d", &op);
- getchar();
- if(op==1){
- add();}
- if(op==3){
- display();}
- if(op==5){
- return 0;}
- return 0;
- }
Add Comment
Please, Sign In to add comment