String Concatenation

This example copies some strings stored in Program memory into a global array. After each string is copied it is added to a buffer using strcat. Finally the resulting string is converted to all upper case using strupr.

Processor: ATtiny 2313

This example was compiled for the 2313 but will run on all processors.*
The calculation takes 3520 cycles and uses the following C code:

#include 
#include 

char string_1[] PROGMEM = "The quick";
char string_2[] PROGMEM = "brown fox";
char string_3[] PROGMEM = "jumped over";
char string_4[] PROGMEM = "the lazy";
char string_5[] PROGMEM = "dog";

PGM_P string_table[] PROGMEM = {
  string_1,
  string_2,
  string_3,
  string_4,
  string_5
};

char sentence[70];

int main(){
  char buffer[12];

  for (unsigned char i = 0; i < 5; i++){
    strcpy_P(buffer,(PGM_P)pgm_read_word(&(string_table[i])));
    strcat(sentence,buffer);
    if(i < 4)
      strcat(sentence," ");
  }
  strcat(sentence,".");
  strupr(sentence);
  
  return 0;
}

The resulting string is stored in ram starting at location 0x60.

*If run on the ATmega238 this location is in the I/O memory rather than sram.