Hello

I done the program below for a CD database but im having a few problems with some of the functions can someone please help me out here ,, ::

First this is when i enter a record i can enter the first set but when i try to enter the second record it only let me enter the first two fields, which are artist and album it then just keeps asking wether i want to continue or not.

Second thing is i cant for some reason enter spaces for the fields, for example an artist with two names will need space in between, every time i use space it reads it as part of the next field.

I would apreciate any help neone can give . please.

#include<stdio.h>

/*********************** SORTING FUNCTION ***************************/
int bubble(int x[],int n)
{
 int hold,j,pass,i,switched = 1;
 for(pass = 0; pass < n-1 && switched == 1;pass++)
 {
  switched=0;
  for (j=0;j<n-pass-1;j++)
   if (x[j]>x[j+1])
   {
    switched=1;
    hold = x[j];
    x[j] = x[j+1];
    x[j+1]=hold;
    }
   }
return(0);
}
/*********************** FILE WRITING FUNCTION ******************************/

void filewrite()
{
  int ch;
  int year[10];
  char label[50],album[50],artist[50];
  
   FILE *fp;
   
  fp = fopen("student.txt","a");
   printf("ENTER Artist, Album , Year , Label \n");
  ch =1;
  while(ch)
  {
  scanf("%s%s%s%d",&artist,&album,&year,&label);
  fprintf(fp,"%s %s %d %s\n",artist,album,year,label);
  
  printf("\n\n press 1 to continue,0 to stop");
  scanf("%d",&ch);
 }
   fclose(fp) ;
}
/******************** OUTPUTING DATA ON SCREEN***************/
void fileprint()
{
  int i,year[10];
  char label[50],album[50],artist[50],x[50];
  FILE *fp;

  
  fp = fopen("student.txt","r");
   i=0;
   printf(" ARTIST         ALBUM         YEAR         LABEL  \n");
   while(!feof(fp))
  {
     fscanf(fp,"%s %s %s\n",&artist[i],&album[i],&year[i],&label[i]);
     printf(" %s          %s          %d          %s\n",artist[i],album[i],year[i],label[i]);
     i=i+1;
   }
   fclose(fp);
   printf("\n\n\nPRESS ANY KEY");
   getch();

  }
/******************* SORTING FILE ************************/
  void filesort()
  { int x[50],n,i,j,year[10];
    char label[50],album[50],artist[50];
    FILE *fp,*fm;

    fp = fopen("student.txt","r");
    fm = fopen("artist.txt","w");
    i=0;
   while(! feof(fp))
    {

     fscanf(fp,"%s %s %d %s\n",&artist[i],&album[i],&year[i],&label[i]);
     x[i]= artist[i];
     i=i+1;
      }

       n=i;

       bubble(x,n);

	for(i=0;i<n;i++)
	{
	printf(" %d\t",x[i]);
	}

 for(i=0;i<n;i++)
 {
   for (j=0;j<n;j++)
   {
   if(x[i]==year[j])
   {
      fprintf(fm,"%s %s %d %s\n",artist[j],album[j],year[j],label[j]);
     }
   }
 }
  fclose(fm);
  fclose(fp);
  printf("\n\n\nPRESS ANY KEY");
  getch();

}
/************************* DATA USING ALBUM***************************/

void albums()
{   int i,ch,year[10];
    char label[50],album[50],album1[50],artist[50];
    FILE *fm;

    ch=1;
  while(ch)
  { 
    fm = fopen("artist.txt","r");
    printf(" \n ENTER ALBUM NAME - ");
    scanf("%s",&album1);
      i=0;
   while(! feof(fm))
    {
     fscanf(fm,"%d %s %d %s\n",&artist,&album,&year,&label);
     if(album1==album)
    {printf("\nARTIST     ALBUM        YEAR        LABEL\n ");
     printf(" %s          %s          %d          %s\n",artist,album,year,label);
     break;
     }
     else
     i=i+1;
      }
  printf("\n\npress 1 to see student info, 0 to return to main menu\n");
  scanf("%d",&ch);
  fclose(fm);
  }



 }

/**************** FUNC. ENDS************************/

void main()
{
  int x[100],n,i,j,c,year[10];
  char label[50],album[50],artist[50];
  
  while(c!=5)
   {  
     
     printf("GIVE CHOICE--\n");
     printf("   1 TO ENTER CD INFO.\n");
     printf("   2 TO SEE STUDENT.TXT FILE\n");
     printf("   3 TO SORT CDs BASED ON ARTIST\n");
     printf("   4 TO SEARCH USING ALBUM NAME\n");
     printf("   5 TO EXIT\n\n--");
     scanf("%d",&c);
     
     switch(c)
	 {
	 case 1:
		  filewrite();
		  break;
	 case 2:
		  fileprint();
		 break;
	 case 3:
		 filesort();
		 break;
	 case 4:  albums();
		  break;
	 case 5:
		  break;
	 default:
		  break;
	 }
    }

  }

Thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.