int ledParp(long *setLedParp){
Serial.println("setLeds: ");
Serial.println(setLedParp[0]);
Serial.println(setLedParp[1]);
Serial.println(setLedParp[2]);
Serial.println(setLedParp[3]);
Serial.println(setLedParp[4]);
Serial.println(setLedParp[5]);
Serial.println(setLedParp[6]);
// here is all good, i can see the data into the array.
Serial.print("length Array: ");
Serial.println(sizeof(setLedParp);
// here is the problem.
Some body know how i can get the legnth of array ?
Some body know how i can get the legnth of array ?
That function knows nothing about an array. It knows about an address in memory where some data is stored. If you want the function to know how much data is stored there, you have two choices. The simplest is to tell it.
The other way, that strings use, is to store in the "array" some value that says "Stop", like the NULL in a string (NULL terminated array of chars) does.
Depending on the nature of the "array", the stop-sign concept may, nor may not, be feasible.
If the data is always in triplets, then a pin number of -1 would indicate that it was time to stop reading from the array. Passing the length of the array to the function may be more reasonable.
I'm not convinced you are using or populating arrays correctly.
I would have expected that you would know the length of the array when you declared it or intialized it- or that you might have declared a dummy value much bigger than the number of positions you might ever use.
Perhaps you could provide some context? Are you reading data of unknown length and then attempting to store it and act on it?
That is not a good use of arrays. What you're really trying to store here is an array of (pin, millis, delay) tuples. It would be better to define a struct to hold that set of values, and then define an array of those structs.
Unlike some other languages, a C array contains NO information about its own length.
The compiler knows the length of arrays (via sizeof()) within the scope of the array definition, but this is lost when you pass the array to other functions (and it becomes a pointer.) So you have to explicitly send the size, if you need it. Or use the special termination value. (and this is why C programs are subject to so many "buffer overflow" attacks.)
DrWizard:
But there seems to be problems passing structures to functions using the Arduino IDE.
There's no 'seems' about it - the Arduino IDE developers didn't consider that people would ever need to use their own types in function signatures. I guess this tells you something about the level of thought that went into this feature. However, the workarounds for this IDE bug are well known.
thk every body for your answers !
the solution of strut sound good.
the solution of array with the length of array is working.
the solution with the marker on ther end of the array sound good too.
the stru is on the .h file
struct info3{
char *nombre[6];
long milis;
int pin;
long delay;
};
the definition the array is: (arrays of struct)
info3 infoA[3];
the objects definition of struct is with the data too.
info3 led1= {{"led1"},44,12,1021};
info3 led2= {{"led2"},22,22,1022};
info3 led3= {{"led3"},33,32,1032};
after i puting the object into the array:
infoA[0] = led1;
infoA[1] = led2;
infoA[2] = led3;
this is the calling to the function:
ledParp3(infoA,0); // primera fila del array.
function:
void ledParp3(struct info3 *dt, int cual) // recibe el tipo de datos info2 que es la estructura y lo muestra como el puntero dt.
{ Serial.print("setLeds2qqqqq: ");
Serial.println(cual);
Serial.println("Puntero_: ");
// for para mostrar el nombre hasta el carater de escape.
Serial.print(dt[cual].nombre[0]);
Serial.print(dt[cual].nombre[1]);
Serial.print(dt[cual].nombre[2]);
Serial.println(dt[cual].nombre[3]);