user53014: I am working on a project where I have to build an IR program that works with all of the AVR/Arduino boards to control the IR devices such as TV, DVD, etc. I am building a struct that can carry the Pronto code information and this is what I have so far:
struct Pronto {
    char* code;
public:
    Pronto(){}
    Pronto(char* code) {
        bool isValid = validateProntoCode(code);
        if(isValid)
            this->code = code;
    }
    Pronto toPronto(char* code) {
        Pronto cde(code);
        return cde;
    }
    void setPronto(char* code){
        bool isValid = validateProntoCode(code);
        if(isValid)
            this->code = code;
    }
    char* toString(){
        return code;
    }
    private:
    bool validateProntoCode(char* code) {
        if(!isInHex(code[strlen(code)-1]))
            return false;
        for (int i = 0; i < strlen(code); i++) {
            if (!isInHex(code[i]) && !(i % 5 == 4 ))
                return false;
            if (i % 5 == 4 && code[i] != ' ')
                return false;
            if (i % 5 == 0 && (!isInHex(code[i]) || !isInHex(code[i] + 1) || !isInHex(code[i] + 2) || !isInHex(code[i + 3])))
                return false;
        }
        return true;
    }
    bool isInHex(char c) {
        char list[22] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'};
        for (int i = 0; i < 22; i++) {
            if (c == list[i])
                return true;
        }
        return false;
    }
};

This struct code 
I can set the Pronto code, validate it, and get the string value from it.
Now, whenever I declare the struct inside the Arduino IDE:
pronto.setPronto("0000 006D 0000 00BF 009F 0031 0030 0010 0010 0031");

I get this following message: 

Sketch uses 4082 bytes (12%) of program storage space. Maximum is 32256 bytes.
Global variables use 2137 bytes (104%) of dynamic memory, leaving -89 bytes for local variables. Maximum is 2048 bytes.
Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint.

Pictures:
https://prnt.sc/ohu4d9
https://prnt.sc/ohu4io
https://prnt.sc/ohu4m8
https://prnt.sc/ohu4pr
https://prnt.sc/ohu4tn
Basically, I just showed all my work on code I did. I commented out any global vars, nothing changed. BUT, when I comment "pronto.setPronto("0000 0000");", I get free space.

So, how can I modify this struct in-order for it not to take allot of space?

The char* code right? That's the problem. Now can you help me modify code or at least tell me how I can resolve this. 

user23644: In your screen shots you are using string literals that are waaaay longer than in your sample code. I suspect using PROGMEM could be a way to work around. But why bothering with constant strings and verify and convert them at run time and not store them as raw data instead? (Also the outcome of the verification for a constant string literal will be always the same. So consider removing verification of your production code.)
uint16_t myParsedProntoCode[] = {
    0x0000, 0x006D, 0x0000, 0x00BF, 0x009F, 0x0031, 0x0030, 0x0010, 0x0010, 0x0031
};

This is much more space efficient as storing a nibble (4 bits) requires only 4 bits instead of 8 bits. So just half the space, not even taking the pointless whitespaces into account.

53014: <p>I am working on a project where I have to build an IR program that works with all of the AVR/Arduino boards to control the IR devices such as TV, DVD, etc. I am building a struct that can carry the Pronto code information and this is what I have so far:</p>

<pre><code>struct Pronto {
    char* code;
public:
    Pronto(){}
    Pronto(char* code) {
        bool isValid = validateProntoCode(code);
        if(isValid)
            this-&gt;code = code;
    }
    Pronto toPronto(char* code) {
        Pronto cde(code);
        return cde;
    }
    void setPronto(char* code){
        bool isValid = validateProntoCode(code);
        if(isValid)
            this-&gt;code = code;
    }
    char* toString(){
        return code;
    }
    private:
    bool validateProntoCode(char* code) {
        if(!isInHex(code[strlen(code)-1]))
            return false;
        for (int i = 0; i &lt; strlen(code); i++) {
            if (!isInHex(code[i]) &amp;&amp; !(i % 5 == 4 ))
                return false;
            if (i % 5 == 4 &amp;&amp; code[i] != ' ')
                return false;
            if (i % 5 == 0 &amp;&amp; (!isInHex(code[i]) || !isInHex(code[i] + 1) || !isInHex(code[i] + 2) || !isInHex(code[i + 3])))
                return false;
        }
        return true;
    }
    bool isInHex(char c) {
        char list[22] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'};
        for (int i = 0; i &lt; 22; i++) {
            if (c == list[i])
                return true;
        }
        return false;
    }
};
</code></pre>

<p>This struct code 
I can set the Pronto code, validate it, and get the string value from it.
Now, whenever I declare the struct inside the Arduino IDE:</p>

<pre><code>pronto.setPronto("0000 006D 0000 00BF 009F 0031 0030 0010 0010 0031");
</code></pre>

<p>I get this following message: </p>

<hr>

<p>Sketch uses 4082 bytes (12%) of program storage space. Maximum is 32256 bytes.</p>

<p>Global variables use 2137 bytes (104%) of dynamic memory, leaving -89 bytes for local variables. Maximum is 2048 bytes.</p>

<p>Not enough memory; see <a href="http://www.arduino.cc/en/Guide/Troubleshooting#size" rel="nofollow noreferrer">http://www.arduino.cc/en/Guide/Troubleshooting#size</a> for tips on reducing your footprint.</p>

<hr>

<p>Pictures:</p>

<p><a href="https://prnt.sc/ohu4d9" rel="nofollow noreferrer">https://prnt.sc/ohu4d9</a></p>

<p><a href="https://prnt.sc/ohu4io" rel="nofollow noreferrer">https://prnt.sc/ohu4io</a></p>

<p><a href="https://prnt.sc/ohu4m8" rel="nofollow noreferrer">https://prnt.sc/ohu4m8</a></p>

<p><a href="https://prnt.sc/ohu4pr" rel="nofollow noreferrer">https://prnt.sc/ohu4pr</a></p>

<p><a href="https://prnt.sc/ohu4tn" rel="nofollow noreferrer">https://prnt.sc/ohu4tn</a></p>

<p>Basically, I just showed all my work on code I did. I commented out any global vars, nothing changed. BUT, when I comment "pronto.setPronto("0000 0000");", I get free space.</p>

<hr>

<p>So, how can I modify this struct in-order for it not to take allot of space?</p>

<hr>

<p>The char* code right? That's the problem. Now can you help me modify code or at least tell me how I can resolve this. </p>
 23644: <p>In your screen shots you are using string literals that are waaaay longer than in your sample code. I suspect using PROGMEM could be a way to work around. But why bothering with constant strings and verify and convert them at run time and not store them as raw data instead? (Also the outcome of the verification for a constant string literal will be always the same. So consider removing verification of your production code.)</p>

<pre><code>uint16_t myParsedProntoCode[] = {
    0x0000, 0x006D, 0x0000, 0x00BF, 0x009F, 0x0031, 0x0030, 0x0010, 0x0010, 0x0031
};
</code></pre>

<p>This is much more space efficient as storing a nibble (4 bits) requires only 4 bits instead of 8 bits. So just half the space, not even taking the pointless whitespaces into account.</p>
