![]() |
|
#1
|
|||
|
|||
i need a little helpthe code down here is one i wrote to convert a digital date to an analogue one.if you compile and run it it will show the wrong month wich is probably due to the fact that arrays start at 0 and not at 1,to compensate for that i used a for loop ithin main to handle this and it worked exept that the program enters the loop and nver comes out.if anyone could fix this little problem for me i'll really appreciate it.
CPP / C++ / C Code:
Last edited by LuciWiz : 07-Mar-2005 at 06:22.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#2
|
||||
|
||||
|
Quote:
Doing this, you allocated 12 elements to your array, starting from index 0 to index 11. Then, you try to access index 12 of the array - but that area of memory doesn't belong to you. Quote:
Instead, start from 0 - this really is allocated, up until 11 (<=11, or <12). So, what are you trying to do here? (I changed the indexes, as you see, so it won't crash or hang) CPP / C++ / C Code:
Is this a test? Well, as for the problem with the indexes, there is a quick fix: you have a 0-based array, but receive data that considers 1 as the starting index; just subtract 1 from the given data and you will have the 2 synchronized. CPP / C++ / C Code:
As a side note, I am really reticent about the use of global variables and cin, although if you are really good it might not get you into trouble. I guess in plain C global variables are OK (some say so, I don't agree I see you are using formal parameters in your functions, but actually you are not using them I'm guessing you had problems with the readout, because you gave the function an int, and the data didn't change after getinputs was called. The trick is to use passing by reference (please read this!) You could do this by using pointers or references (in case you work in C++) With pointers: CPP / C++ / C Code:
Using references: CPP / C++ / C Code:
I went along with the code you wrote so far so you would understand it, but you may want to stick to C or C++... I hope this is OK. Kind regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
|||
|
|||
thanks a bunchthe pointer method make a lot more sence and is a lot more efficient.thanks a lot,i read a little more on pointers and i think i'm ready to play around with them now.
thanks a bunch ciao |
Recent GIDBlog
Halfway done! by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The