stevemarple / IniFile

Arduino library to parse ini files.
GNU Lesser General Public License v2.1
87 stars 45 forks source link

Unable to read the data inside a file #10

Closed surajparab945 closed 7 years ago

surajparab945 commented 7 years ago

Hii,

I want to read the maximum profiles and order in which it is stored, for that, I am storing the data in a pointer array from buffer. When I am using the pointer array outside the loop it show me nothing as if data has been not stored ? I can see the data in buffer using Serial monitor and also using pointer array. I can see the data but only in a loop and if I print outside the loop It doesn't print anything. It will be more clear when I will provide the code. char *SP[80]; void setup() { // debug output at 9600 baud Serial.begin(9600);

pinMode(10,OUTPUT); // setup SD-card Serial.print(F("Initializing SD card...")); if (!SD.begin(10)) { Serial.println(F(" failed!")); while (true); }

Serial.println(F(" done."));

//INI FILE const char *filename = "/config3.ini"; const size_t bufferLen = 80; char buffer[bufferLen];
IniFile ini(filename); if (!ini.open()) { Serial.print("Ini file "); Serial.print(filename); Serial.println(" does not exist"); //error("Ini Setting File Does NOt Exist"); } Serial.println("Ini file exists");

// Check the file is valid. This can be used to warn if any lines // are longer than the buffer. if (!ini.validate(buffer, bufferLen)) { Serial.print("ini file "); Serial.print(ini.getFilename()); Serial.print(" not valid: "); //error("Setting File Is Not Valid"); } // to Determine the number of profiles and it's order do {

j = j + 1;  // int 1

itoa(j, number, 10); // number to String 1

if( ini.getValue("PROFILES", number , buffer, bufferLen)){

SP[j]= buffer; Serial.println(SP[j]);

count = j;

} else{

  buffer[0] = '\0';

}

} while(buffer[0] != '\0' );

Serial.print("MAXIMUM SOUND PROFILES:");

Serial.println(count); ini.close();

for(int i = 0; i <= count; i++){

Serial.println(SP[i]);

} }`

stevemarple commented 7 years ago

What does the config3.ini file look like?

surajparab945 commented 7 years ago

[PROFILES] 1=PROFILE1 2=PROFILE5

[PROFILE1] sound_file_name1 = "/SoundP~1/bell.wav"

Volume Parameters

A1 = 10 B1 = 0

Speed Parameters

C1 = 0 D1 = 1

Silence Parameters

E = 0 F = 1000

[PROFILE2] sound_file_name2 = /SoundP~1/steam.wav

Volume Parameters

A2 = 1 B2 = 1

Speed Parameters

C2 = 20 D2 = 0

Silence Parameters

E = 1 F = 0

surajparab945 commented 7 years ago

This is the output where I get the profiles in do while loop but afterwards when I access outside the do while loop I get blank.

Initializing SD card... done. Sound directory Ini file exists PROFILE1 PROFILE5 PROFILE4 PROFILE2 PROFILE3 MAXIMUM SOUND PROFILES:5

Ini file exists "/SoundP~1/bell.wav"

stevemarple commented 7 years ago

You are storing the buffer pointer in SP. The buffer pointer does not change but its contents do. You must copy the buffer contents to a char array.