Who wrote MyString.h and MyString.cpp ?
I wrote this little lib, because when I started writing this scketch, I was not sure if the strlib commands were already integrated into the Arduino library. I have already taken the initiative to write my own commands. Also, when I created another sketch that involves many LCD printing functions, for some reason, which I did not debug, the sketch showed some bugs, and with my lib everything went well apparently. So I kept using my lib.
When we want to try your sketch, we need the latest version of all the files that you use.
MyString.h
#ifndef MyString_h
#define MyString_h
#include "Arduino.h"
class MyString {
public:
MyString();
void
put(char *buffer, const char *str),
catenate(char *str0, const char *str1),
catenate(char *str, const char chr),
catenate(const char chr, char *str),
put_P(char *buffer, const char *str),
catenate_P(char *str0, const char *str1);
private:
};
#endif
MyString.cpp
#include "Arduino.h"
#include "MyString.h"
MyString :: MyString() {
}
void MyString :: put(char *buffer, const char *str) {
byte i; // counter;
for(i = 0; str[i]; i++) buffer[i] = str[i];
buffer[i] = '\0';
}
void MyString :: catenate(char *str0, const char *str1) {
byte i, j; // counters;
for(i = 0; str0[i]; i++);
for(j = 0; str1[j]; j++) str0[i + j] = str1[j];
str0[i + j] = '\0';
}
void MyString :: catenate(char *str, const char chr) {
byte i; // counter;
for (i = 0; str[i]; i++);
str[i] = chr;
str[i + 1] = '\0';
}
void MyString :: catenate(const char chr, char *str) {
byte i; // counter;
for(i = 0; str[i]; i++);
i++;
for( ; i; i--) str[i] = str[i - 1];
str[0] = chr;
}
void MyString :: put_P(char *buffer, const char *str) {
byte i; // counter;
for(i = 0; pgm_read_byte(str + i); i++) buffer[i] = pgm_read_byte(str + i);
buffer[i] = '\0';
}
void MyString :: catenate_P(char *str0, const char *str1) {
byte i, j; // counters;
for(i = 0; str0[i]; i++); // identifies the end of str0;
for(j = 0; pgm_read_byte(str1 + j); j++)
str0[i + j] = pgm_read_byte(str1 + j);
str0[i + j] = '\0';
}
Are you sure that you have calculated the lastSTR properly ? Why strip the last element with "- 1" ?
The last concatenation of the for loop should be between the penultimate and last element of the STR []
You can start with something that works:
I'm beginning to understand the correct way to use the pgm_read commands. I am interpreting your suggested code as I reread the references. ![]()