Ok i decided to start from scratch for my CD database.
I've created an array structure, i can enter the fields, but for some reason it dont display to screen neone know why please???
also how can i add an option to either add more records or just quit . tried it with a while loop didnt work..
here is the program i've done so far....
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Idea here is to enter an array of structures
// write them to disk and read them back
// simple structure
struct tuple {
char artist[50];
char album[50];
char label[50];
int year[4];
char type[30];
};
int main() {
// file pointer
FILE * mydata;
// structures
struct tuple myDB[3];
struct tuple otherDB[3];
// variable needed
int i;
// go through each record
// write each to disk using formatted output
mydata = fopen("mymusic.txt","w");
for (i=0; i<2; i++) {
printf("Enter the artist: \n");
scanf("%s",myDB[i].artist);
printf("Enter the album: \n");
scanf("%s",myDB[i].album);
printf("Enter label name: \n");
scanf("%s",myDB[i].label);
printf("Enter year: \n");
scanf("%d",&myDB[i].year);
printf("Enter the type of music: \n");
scanf("%s",&myDB[i].type);
fprintf(mydata, "%s %s %s %d %s\n",myDB[i].artist, myDB[i].album, myDB[i].label,myDB[i].year,myDB[i].type);
//printf("\n\n press 1 to continue,0 to stop");
// scanf("%d",&ch);
}
fclose(mydata);
// read the data
printf("reading data...\n");
mydata = fopen("mymusic.txt","r");
for (i=0; i<2; i++) {
fscanf(mydata,"%s %s %s %d %s",otherDB[i].artist, otherDB[i].album, otherDB[i].label, &otherDB[i].year, otherDB[i].type);
printf("Record is...\n");
printf("%s\n",otherDB[i].artist);
printf("%s\n",otherDB[i].album);
printf("%s\n",otherDB[i].label);
printf("%d\n",otherDB[i].year);
printf("%s\n",otherDB[i].type);
}
fclose(mydata);
}