English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Is there any datat types to assign dynamic data's to an array?

I mean I would like to assign datas dynamically in a real time environment. I need to pass those dynamic datas to a variable and need to use it with an array.( the variables inside the array should contain the updated as soon as the variables value changed)

Ex:

#include

a1=p1.0;
a2=p2.0;
...upto

a16=p16.0; // The value of p1.0 will vary dynamically and the values assigned to a1, a2,.. a16 must be passed to the array I am going to use inside the main.

Main()

{
int i;
char c[]={a1,a2,...a15}

for(i=0;i<=15;i++)
{
if( c[i]==1)
{
bla bla..
}
}
}

2007-08-29 19:45:20 · 4 answers · asked by Kannan 1 in Computers & Internet Programming & Design

4 answers

First, you have totally mixed concept of dynamic data type with your so called dynamic data here.

What you are talking here is about the ports on some system [probably some evaluation board in embedded system or some port from your computer].

Now you want to assign those values in your array. Please understand that though these values are varying at those port pins, it does not mean that by assigning variables in array it will automatically vary inside the array also.

So first thing is you can not assign dynamically modified value to some variable until some kind of event tells you about the value modification at source [Px.0 in your case].

Here even if you assign those values [a1,a2 etc] to array, still those will not be the current values at Px.0 as your Px.0 is modifying itself very fast.

So you either just assign those variables to your array one by one as c[0]=a1; c[1]=a2;...c[14]=a15;

Or have some timer event based on which you will do above functionality after some time intervals so that you get updated values periodically.

That's all I can say after looking at your incomplete, confusing question and the code. Make sure that you put your code and question completely [or code where actual problem is]. Still if you have anymore doubts then send me an email, I will try to help you.

2007-08-29 21:45:29 · answer #1 · answered by Amit 2 · 0 0

ya
if i m getting u right then i guess what u want is to change certain data stored in u r array at the time of executing the progrm

this can be done by creating an array of pointers n then changing the value stored in the pointer
in this way u will have the pointer value i.e addresses that r, will remain same but the value in them will change
thus u r purpose is solved

2007-08-30 05:39:51 · answer #2 · answered by Anonymous · 0 0

Hi,
U may declare ur array-the one u r using in main(), as global variable, whenever or anywhere u assign any value to elements of this array, u may access these values in ur main() and u need not pass this array also;

2007-08-30 03:15:25 · answer #3 · answered by iqbal 4 · 0 0

ur question is pretty much unclear,
if u are asking about dynamic data type then try templates in c++ and i dont see any other solutions in c.
but from ur example, its unclear and confusing to give the exact answer.

2007-08-30 03:07:02 · answer #4 · answered by i_am_the_next_best_one 5 · 0 0

fedest.com, questions and answers