Shop OBEX P1 Docs P2 Docs Learn Events
char array — Parallax Forums

char array

Hello, I am new to doing this and am having some trouble. the directions I have are to use "char array" instead of "int array" to determine how many bytes each element has. I have tried changing int array to char array but get an error. Any suggestions on what I am doing wrong. Many thanks for the help.

#include "simpletools.h" // Include simpletools library

int array[5] = {11, 13, 17, 19, 23}; // array

int main() // Main function

{
print("array start address = %d \n\n", array); // Display array value

for(int i = 0; i < 5; i++)
{
print(" array[%d] = %d \n", i, array); // Display array value
print("&array[%d] = %d \n", i, &array); // Display array address
}
}

Comments

  • Hal AlbachHal Albach Posts: 747
    edited 2017-04-17 01:33
    Running your program on my activity board yields no errors, whether array is int or char.
    However, your final print statements will only output the address of array, 8036 in my case. Adding the subscript i to array and &array yielded what you wanted per your comments.
    print(" array[%d] = %d \n", i, array[i]); // Display array value
    print("&array[%d] = %d \n", i, &array[i]); // Display array address
    
  • Saying "get an error" is not very helpful. Giving the error description and location is much more useful.
  • Thanks for the feedback, I will make sure to include the error description.
Sign In or Register to comment.