MP3 Programming

Opening a file

Page 1 of 1

4 Replies - 1855 Views - Last Post: 15 February 2012 - 04:05 AM Rate Topic: -----

#1 dil73  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-April 10

MP3 Programming

Posted 18 April 2010 - 12:35 PM

I need to build a programme to reload the data from a file to the MP3 player. I have already written the code but when I run the programme and compiler the DOS window flashes on for a second and then closes without giving me a chance to see if there are any problems. My code is probably too large to post here. Can you give me any idea why the DOS window does not remain open for me to see the result?

Many thanks

Dilshad
Is This A Good Question/Topic? 0
  • +

Replies To: MP3 Programming

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: MP3 Programming

Posted 18 April 2010 - 12:37 PM

This post may be your answer.
Was This Post Helpful? 0
  • +
  • -

#3 dil73  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-April 10

Re: MP3 Programming

Posted 18 April 2010 - 12:38 PM

I need to build a programme to reload the data from a file to the MP3 player. I have already written the code but when I run the programme and compiler the DOS window flashes on for a second and then closes without giving me a chance to see if there are any problems. My code is probably too large to post here. Can you give me any idea why the DOS window does not remain open for me to see the result?

Many thanks

/**

*/
#include <stdio.h> // Standard Input/Output Library use f or printf() and scanf() functions.
#include <stdlib.h> // Standard Library - Used for system() function.
#include <string.h>
#include <time.h>

// Define Constants //
#define MAXSONGREC 100
#define MAXLENGTH 40

////////////////////////////////////////////////////////////////////
/////////////////// Structures /////////////////////////////////////
////////////////////////////////////////////////////////////////////
struct
{
    char title[MAXLENGTH];
    char artist[MAXLENGTH];
    char genre[MAXLENGTH];
    int year;
    float time;
    char fileLocation[MAXLENGTH];
} trackInfo[MAXSONGREC];

////////////////////////////////////////////////////////////////////
//////////////////***Prototypes--Function***////////////////////////
////////////////////////////////////////////////////////////////////

int trakOption(void);

////////////////////////////////////////////////////////////////////
////////////////////////**** Main Function ****//////////////////////
////////////////////////////////////////////////////////////////////
int main(void)
{
      int arrayTrack = 0, position = 0, menuchoice = 0; // Declare and Initilise Variables.
      FILE *fp;      
      
      fp = fopen("trackDetails.text", "rt");           // open a file where stored the Song record
      
      if(fp == NULL)
      {
           printf("\nUnable to open Database. May not found or corrupted.\n");
           exit(EXIT_FAILURE);
      }
      else
      {
           fscanf(fp, "%d\n", &arrayTrack);
           
           // printf("%d\n", arrayTrack size);
           for(position = 0; position < arrayTrack; position++)
           {
                fgets(trackInfo[position].title, sizeof(trackInfo[position].title), fp);
                fgets(trackInfo[position].artist, sizeof(trackInfo[position].artist), fp);
                fgets(trackInfo[position].genre, sizeof(trackInfo[position].genre), fp);
                fscanf(fp, "%d\n", &trackInfo[position].year);
                fscanf(fp, "%f\n", &trackInfo[position].time);
                fgets(trackInfo[position].fileLocation, sizeof(trackInfo[position].fileLocation), fp);
           }
           
           while(menuchoice != 6) // Another loop to run the program until quit.
           {
                 printf("\nWELCOME TO RUSKIN-POD MP3 PLAYER :\n");
                 printf("\n==================================\n");
                 printf("\n1. Track Option:");
                 printf("\n2. Current Track list to a disk File : ");
                 printf("\n3. Display all track and current Track : ");
                 printf("\n4. Space free percent : ");
                 printf("\n5. Create playlist by selcting number : ");
                 printf("\n6. End Program");
                 
                 printf("\n\n");
                 
                 scanf("%d", &menuchoice);
                 
                 switch(menuchoice)               
                 {
                        case 1:
                            printf("\nTrack Option : \n"); 
                            printf("\nYou select Track option :");
                            printf("\n=========================\n"); 
                            
                            int choice; int nb_song; song_nb;
                            int arrayTrack;                           
                            
                            while(choice != 4)
                            {
                                    printf("\n1. Add Track: ");
                                    if(nb_song < MAXSONGREC)
                                    {
                                               printf("\nEnter Song number: ");
                                               scanf("%d", &nb_song);
                                               arrayTrack[nb_song] = song_nb;
                                               nb_song= nb_song + 1; // or nb_song++
                                               
                                               
                                               
                                               
                                    }
                                    else
                                    {
                                              printf("\nSorry, The MP3 Pod is Full.");
                                    }              
                            
                            break;
                        case 2:
                            printf("\n2. Current Track list to a disk File : ");
                            printf("\n=====================================\n");
                        // Invoke Playlist Manager Function
                            printf("Song: %s\n", trackInfo[1].title);
                            break;
                        case 3:
                            printf("\n3. Display all track and current Track : ");
                        // Display Info track list which is recorded in database
                            int arraytrack;
            
                            for(position = 0; position < arraytrack; position++)
                            {
                                    printf("%s", trackInfo[position].title);
                                    printf("%s", trackInfo[position].artist);
                                    printf("%s", trackInfo[position].genre);
                                    printf("%d", trackInfo[position].year);
                                    printf("\n%f", trackInfo[position].time);
                                    printf("\n%s\n", trackInfo[position].fileLocation);
                            }
                        case 4:
                            printf("\n4. Space free percent : ");
                            printf("\n======================\n");
                             
                            break;
                        case 5:
                            printf("\n5. Create playlist by selcting number : ");
                            printf("\n=====================================\n");
                             
                            break;
                        case 6:                      
                            printf("\nTHANK YOU FOR PLAYING RUSKIN POD MP3 PLAYER. GOOD BYE.\n\n");
                            break;
                        default:
                            printf("\nInvalid choice. Please rpeat your choice again 1 to 4");
                            printf("\n========================================================\n");
                            break;
                 }
           }
      }
      fclose(fp);
      
      printf("\n\n");
      system("pause");
      
      return 0;
}

////////////////////////////////////////////////////////////////////
////////////////// User-Defined Functions //////////////////////////
////////////////////////////////////////////////////////////////////
////////////////// Track delete Function ///////////////////////////

int trackOption(void)
{
    int trackChoice = 0, deleteTrack=0, position;
    
    while(trackChoice != 5)
    {
            printf("\nTrack Option Activity. Please choose your option: \n");
            printf("\n1. Add Track to Database : ");
            printf("\n2. Delete Track From Database");
            printf("\n3. Play Individual Track");
            printf("\n5. Return to Main Program");
            printf("\n=========================\n");
            
            scanf("%d", &trackChoice);

            switch(trackChoice)
            {
            case 1:
            // Code to Add Track
            case 2:
            // Code to Play Track
            case 3:
            // Code to Delete Track
            case 4:
                 
            printf("\nDISPLAY ALL TRACK RECORDED IN DATABASE\n");
            printf("\n=========================================\n");
            int arraytrack;
            
            for(position = 0; position < arraytrack; position++)
            {
                    printf("%s", trackInfo[position].title);
                    printf("%s", trackInfo[position].artist);
                    printf("%s", trackInfo[position].genre);
                    printf("%d", trackInfo[position].year);
                    printf("\n%f", trackInfo[position].time);
                    printf("\n%s\n", trackInfo[position].fileLocation);
            }
            
            break;
            case 5:
            printf("\nExiting Track Option.");
            break;
            default:
            printf("\nReturn to Main function. Please select a number from 1 to 5.");
            break;
            }
    }
    
    system("pause");
}




Dilshad

Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)
Was This Post Helpful? 0
  • +
  • -

#4 UG Cyber  Icon User is offline

  • D.I.C Addict

Reputation: 32
  • View blog
  • Posts: 550
  • Joined: 24-July 08

Re: MP3 Programming

Posted 18 April 2010 - 12:48 PM

:code:
try using getchar(); prior to any return statement.
Was This Post Helpful? 0
  • +
  • -

#5 dil73  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-April 10

Re: MP3 Programming

Posted 15 February 2012 - 04:05 AM

This code is remove for study case reason

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1