C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-28-2009, 07:20 PM   #1
Registered User
 
Join Date: Mar 2008
Posts: 47
constant structure array - hlep please

I've got a constant structure array that represents a song, i declare another const struct of the same type and make this constant structure array = the other one, what is the correct code


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;
//***********************************************
I am getting the error where I decalare "Song" and make it = "Saints"
ie at this code:
Code:
const Note_Beats Song = Saints;
help please!
dezz101 is offline   Reply With Quote
Old 10-28-2009, 07:38 PM   #2
Registered User
 
Join Date: Mar 2008
Posts: 47
can you not make an array equal to another array or something??? sooo consfused :
dezz101 is offline   Reply With Quote
Old 10-28-2009, 08:01 PM   #3
Registered User
 
hk_mp5kpdw's Avatar
 
Join Date: Jan 2002
Location: Northern Virginia/Washington DC Metropolitan Area
Posts: 2,870
Code:
const Note_Beats Song = Saints;
When Song is pushed onto the stack, it's set to be const. Then you try and assign something to it but it's already const and you can't change something that's const. You could do it just like you did for the first const struct... or in C++ you could create a constructor for the struct and do the following:
Code:
const Note_Beats Song(Saints);
but I'm afraid your options are limited in C. Would a memcpy of the contents work perhaps (copying from one const struct to another)?
__________________
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
--Charles Babbage, 1792-1871

09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
hk_mp5kpdw is offline   Reply With Quote
Old 10-28-2009, 08:09 PM   #4
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,642
Why don't you just make a list of songs, and wander through it with a pointer?


Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 10-28-2009, 08:29 PM   #5
Registered User
 
Join Date: Mar 2008
Posts: 47
Quote:
Originally Posted by hk_mp5kpdw View Post
Code:
const Note_Beats Song = Saints;
When Song is pushed onto the stack, it's set to be const. Then you try and assign something to it but it's already const and you can't change something that's const. You could do it just like you did for the first const struct... or in C++ you could create a constructor for the struct and do the following:
Code:
const Note_Beats Song(Saints);
but I'm afraid your options are limited in C. Would a memcpy of the contents work perhaps (copying from one const struct to another)?
Im not trying to change the value of the const, im declaring it and setting it to be equal to the const Saints struct

and what is this code going to do??
Code:
const Note_Beats Song(Saints);
doesnt make any sense to do this???
dezz101 is offline   Reply With Quote
Old 10-29-2009, 01:17 AM   #6
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,785
You are trying to assign an array to a single element. How can you fit several rooms inside one room?
The line of code you are confused about is C++ syntax. If you do not use C++, you can ignore it.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 10-29-2009, 05:30 AM   #7
Epy
I like turtles
 
Join Date: Sep 2009
Location: Ohio
Posts: 322
Code:
{ {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} }
It lets you assign C6 etc for the int note part? Should have a 0x in front of that if it's supposed to be hex.
__________________
-Jake
http://thatcadguy.blogspot.com/
Epy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot allocate an array of constant size 0 steve1_rm C Programming 9 05-26-2009 03:57 AM
Syntax for constant array of array pointers BMintern C Programming 4 05-14-2008 08:21 AM
2D array becoming "deallocaded" Aaron M C Programming 2 09-23-2006 07:53 AM
Filling an array in a structure thephreak6 C Programming 1 12-16-2002 06:05 PM
Hi, could someone help me with arrays? goodn C Programming 20 10-18-2001 09:48 AM


All times are GMT -6. The time now is 12:29 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22