This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Arrays

As a fairly new student in C I am having diffictly with arrays.

I have a string of numbers that I am tring to split up into smaller strings to convert them to integers.

I have made the code as basic as possible but still get the errors.

#include <stdio.h>
#include <stdlib.h>
#include <reg52.h>

xdata char Temperatures1[9];
xdata char Temperatures2[12];
xdata char Temperatures3[9];

void main(void)
{

  char a[36] = "<<123456789012345678901234567890>>";
  int s;

    SCON = 0x52;
    TMOD = 0x20;
    TCON = 0x69;
    TH1  = 0xF5;

    for(s=0; s < 9; s++)
    {
     Temperatures1[s] = a[s+2];
    }

    for(s=0; s < 12; s++)
    {
     Temperatures2[s] = a[s+11];
    }

    for(s=0; s < 9; s++)
    {
     Temperatures3[s] = a[s+23];
    }

    printf("Temperatures1: %s\n", Temperatures1);
    printf("Temperatures2: %s\n", Temperatures2);
    printf("Temperatures3: %s\n", Temperatures3);
}
I'd expect that Temperatures1,2,3 would all be 1234567890. But Temperature1 is the entire string and Temperatures 2,3 are both incorrect as well

When I watch what is happening in the watch window of the simulator I can see the error ocurring but don't know how to fix it.

Any ideas

Cheers

Steve