Bytes of stored words.

I have a char array with three words and I am trying to find out how many bytes are necessary to store the actual 3 words of data stored in the array. If anyone can help me I would appreciate it. I think you use sizeof() but I am not sure.

Thanks,
R.

Here is my char array code:

 
  char words[3][9] = {"Zinc", "Artifact", "Zilch"};
Minimum amount of bytes you can fit all three words?

It will be length of all words + count of words: 1 byte per character + 1 byte per word for trailing 0.
You are better off using strlen: http://www.cplusplus.com/reference/cstring/strlen/
1
2
3
4
char words[100] = "Zinc";
int i = strlen(words);
int j = sizeof(words);
std::cout << i << " " << j;
4 100
Last edited on
Thanks everyone for your information. This helps me a lot.

Thanks!
r.
Topic archived. No new replies allowed.