Want to put a letter into an uint8_t...

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have an array of uint8_t's. It has to be that way I believe because it will hold a lot of binary data. I do, however, want to put a word in the front part of it. I'm trying to do the following:

uint8_t my_list[20];

my_list[0] = "W";
my_list[1] = "O";
my_list[2] = "R";
my_list[3] = "D";

That doesn't work as I get the warning: assignment makes integer from pointer without a cast.

Well, I try doing a cast like this:

my_list[0] = (uint8_t)"W";

And I get this error: cast from pointer to integer of different size.

Obviously I'm doing something wrong but googling hasn't gotten me too far on either error message. Any tips?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
uint8_t my_list[20]; 

my_list[0] = 'W'; 
my_list[1] = 'O'; 
my_list[2] = 'R'; 
my_list[3] = 'D'; 

BTW, in C, strings are terminated by '\0'.

/Martin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Removed due to not reading clearly...

Last Edited: Mon. Mar 1, 2010 - 06:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks! Single quotes did the trick!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why wouldn't you just:

uint8_t my_list[20]= { "WORD" };

or do you not want the NUL at my_list[4]?

In fact if you don't want to waste 20 bytes to hold something that would fit in 5 then:

uint8_t my_list[]= { "WORD" };

which will auto-dimesion the array to 5 bytes to hold 'W','O','R','D',0x00

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks! I was looking for a way to paste in a whole string like that. The null byte will be overwritten later anyhow so that should work great.