Hello,
I have a function took String as CSV text ( "text,text,text,...,#") then return array of Strings contain the sub-strings witch is inside this CSV string. after that i use this array to set data into class variables, with Set functions that was already built.
I refer the this link https://www.geeksforgeeks.org/return-local-array-c-function/ to build the Structure and the function and they are working properly.
but while I tried to call the function from the void loop() it returned arrays took the exact values mentioned , but when i tried to call it from another function it returns a empty value.
I defined my Structure:
**struct arrStructure { **
** String arr[100]; **
};
And this is my function:
struct arrStructure distrCsvMsgIntoStrgAry(String csvData)
{
** int commasCount = 0;**
** for (unsigned int i = 0; i < csvData.length(); i++)**
** if (csvData.charAt(i) == ',')**
** commasCount++;**
** int partsCount = commasCount + 1; **
** struct arrStructure stringTo;**
** int partsIndex = 0;**
** int indexOfComma = csvData.indexOf(','); **
** while (partsIndex < partsCount)**
** {**
** stringTo.arr[partsIndex] = csvData.substring(0, indexOfComma);**
** csvData = csvData.substring(indexOfComma + 1, csvData.length()); **
** indexOfComma = csvData.indexOf(','); **
** partsIndex++;**
** }**
** return stringTo; **
}
when i need covert CSV String data to Array of Strings :
String dataRecived="confS,A,0,0,150,-5,6,70000,4-20mA,Flow Meter,m3//hr,#";
struct arrStructure stringTo = distrCsvMsgIntoStrgAry(dataRecived);
Serial.println(stringTo.arr[0]); Serial.println(stringTo.arr[1]); Serial.println(stringTo.arr[2]);
when i type this orders inside the void loop() the serial print :
confS
A
0
but if i use same 3 line within another function inside my Program, the serial returns empty values.
kindly help me to solve my problem
Thank you