Thread: const structure array declaration

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    53

    const structure array declaration

    Hey guys, im trying to write some code for a micro-controller outputs to a little speaker a song that is programed in C, but I want to make it so that it can play other songs just by changing where its says "change song here", but I get an error when I say

    "
    Code:
    const Note_Beats Song = Saints;
    " why??? and how can I fix this???

    Code:
    //**************************
    typedef struct 
    {
      int note;
      int beats;
    }Note_Beats;
    //**************************
    
    
    
    //***********************************************
    //***************Song list***********************
    //***********************************************
    
    //********When The Saints Go Marching In*********
    #define NumberOfBeats_Saints 16
    const Note_Beats Saints[NumberOfBeats_Saints] = { {C6, 1}, {E6, 1}, {F6, 1}, {G6, 5},      {C6, 1}, {E6, 1}, {F6, 1}, {G6, 5},       {C6, 1}, {E6, 1}, {F6, 1}, {G6, 2}, {E6, 2}, {C6, 2}, {E6, 2}, {D6, 5} };
    //***********************************************  
      
    //**************Choose Song Here*****************
    #define NumberOfBeats = NumberOfBeats_Saints
    const Note_Beats Song = Saints;
    //***********************************************

  2. #2
    Registered User
    Join Date
    Mar 2008
    Posts
    53
    I guess my #define should'nt have that '=' there, I have taken it out but that is not the issue still

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You don't use = in macros ... well I suppose you could in theory some place, but not the way you're doing it. Macros are text substitution. Wherever it sees 'NumberOfBeats', it replaces that with '= NumberOfBeats_Saints'.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    53
    Yer my fault lol, I used to have const ints instead of the #defines and I left the = in there

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    53
    Any ideas guys???

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Any ideas what? What's your problem now? Make a small functional program and explain what you mean to do, versus what's happening.

    Edit: Actually, pick one thread, not two. You have two going for the same topic.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM