Q:

Data from UART to update an array

Hope someone can help me here. Fairly new to C (come from a PHP background) and been stuck on this problem couple days now. Still trying to get head round pointers etc, a joy PHP doesn't have.
So basiclly, I want to be able to update a specific value within the array to a value given via the UART. The UART is all working correctly. Just cant get the code to work to update the array. Data from the UART, will be in the string 'uart' in the code below and will have the value '0430' (First 2 digits refer to the array key and the 2nd two will be the value to update it to).
// Array values
int unsigned array[15] = {05,76,33,02,11,07,34,32,65,04,09,32,90,03,44};

// Split the UART string into required parts
// Array Key
int key;
memcpy (key, &uart[0], 2);
// New Value
int value;
memcpy (value, &uart[2], 2);

array[key] = value; // Im sure this is wrong and needs to be done via a pointer?

The new array should now be:
    {05,76,33,02,30,07,34,32,65,04,09,32,90,03,44};
Any advice would be great and even a short explaination would be superb to help me understand.
Thanks in advance

A:

You cannot simply copy the two bytes from the string "04" to an int variable and expect it to contain 4. You need to convert the string "04" into the value 4, for example by using atoi
You want this:
  char uart[] = "0430";   // made up uart buffer just for debugging
  char temp[3] = { 0 };   // buffer for 2 char string, all 3 bytes initialized to 0

  temp[0] = uart[0];
  temp[1] = uart[1];      // temp contains now "04"

  int key = atoi(temp);   // convert from string to integer, key now contains 4

  temp[0] = uart[2];      
  temp[1] = uart[3];      // temp contains now "30"

  int value = atoi(temp); // convert from string to integer, value now contains 30

