Thread: Having Trouble Passing typedef Arrays to a Function

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    36

    Having Trouble Passing typedef Arrays to a Function

    I am noob to working with typedef and and arrays. I need to pass them to a function that inputs the info in to the arrays from a file songData.txt. I am getting these errors but I am stuck. I am pretty sure there is something wrong with the data types from the errors but I just cant see what I am doing wrong and I cant make any more progress untill I get the file put in the parallel arrays.

    Thanks in advance for any help!

    Errors:
    E:\Music\music.c(21) : error C2087: '<Unknown>' : missing subscript
    E:\Music\music.c(25) : error C2087: '<Unknown>' : missing subscript
    E:\Music\music.c(95) : error C2087: '<Unknown>' : missing subscript
    E:\Music\music.c(96) : error C2055: expected formal parameter list, not a type list
    E:\Music\music.c(102) : warning C4133: 'function' : incompatible types - from 'char [6]' to 'struct _iobuf *'
    E:\Music\music.c(102) : warning C4133: 'function' : incompatible types - from 'int [1]' to 'const char *'

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #define NUMBER 4
    #define ARRAYSIZE 15
     
    //                        0         1          2        3
    typedef enum SongType {COUNTRY, DANCEPARTY, ELEVATOR, ROCK} SongType;
    typedef int SongArray[ ];
    
    void PrintMenu(int*);
    
    void ReadMusicData(FILE*, SongArray[], SongType[]);
    
    int main()
    { 
     SongArray playList[ARRAYSIZE];
     
     SongType song[ARRAYSIZE];
    
     int seed, menuChoice=0;
    
     FILE* inFile;
     // opens the file for read only
     inFile = fopen("songData.txt", "r");
     // test to make sure file opens 
    
     if (!fopen("songData.txt", "r"))
    	{
    	printf("File Opening Failed!\n"
    	       "Please ensure file is present and restart!\n");
    			//EXECUTION DONE, NEED TO ADD FLAG
    	}
    
     seed = time(NULL);
    
     srand(seed);
    
     PrintMenu(&menuChoice);
    
     printf("You chose %d\n", menuChoice);
    
     ReadMusicData(inFile, playList, song);
    
     return 0;
    }
    
    void PrintMenu(int *menuChoice)
    {
     printf ("*******************************************\n"
                 "WELCOME TO THE JLH05G MUSIC PLAYER!\n"          
             "********************************************\n\n"
             "Please Choose a Menu Choice 1, 2, 3, or 4\n"
    	 "1: Play Current Playlist In Order\n"
             "2: Play Randomized Playlist\n" 
             "3: Play One Song\n" 
             "4: Leave the Program\n");
     
     scanf("%d", menuChoice);
    
     while ((*menuChoice < 1) || (*menuChoice > 4))
    	{
    	printf ("Please Choose a Menu Choice 1, 2, 3, or 4\n"
    			"1: Play Current Playlist In Order\n"
    			"2: Play Randomized Playlist\n" 
    			"3: Play One Song\n" 
    			"4: Leave the Program\n");
    
    	scanf("%d", menuChoice);
    	} 
    
     printf("You chose %d\n", *menuChoice);
      
     return;
    }
    
    void ReadMusicData(FILE*, SongArray playList[], SongType song[])
    {
     int i, j;
     char typeCode;
    
     for(i=0; i<ARRAYSIZE; i++)
            {
    	 fscanf("%d %c", playList[i], typeCode);
    
    	switch (typeCode)
    		{
    			case 'C': song[j] = COUNTRY;
    					break;
    			case 'D': song[j] = DANCEPARTY;
    					break;
    			case 'E': song[j] = ELEVATOR;
    					break;
    			case 'R': song[j] = ROCK;
    					break;
    		}
            }
    }
    songData.txt
    Code:
    1012 C
    25 E
    34567 R
    987789 D
    123 D
    45320 D
    555 R
    123456 E
    40506 R
    111 E
    13 R
    12 C
    1213 D
    44444 R
    19191 C
    EDIT:found and fixed last bracket error and missing semicolon, reposted errors.
    EDIT:removed square brackets from arrays in function call, reposted errors.
    old function call = ReadMusicData(inFile, playList[], song[]);
    Last edited by jlharrison; 03-27-2006 at 11:49 AM.

  2. #2
    Registered User
    Join Date
    Jan 2006
    Posts
    36
    Adding the constant ARRAYSIZE to the typedef gets rid of the 3 error 2087s but I dont think this is the correct way to fix the problem.
    Code:
    typedef int SongArray[ARRAYSIZE];
    If that is correct I still dont know how to deal with the other errors.
    This can also serve as a *^bump^*
    Last edited by jlharrison; 03-27-2006 at 12:08 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM