Skip to main content
added 1 character in body
Source Link
Code Gorilla
  • 5.7k
  • 1
  • 17
  • 31

This may not be your only issue, but I think you are using sizeof() wrongly. This 'function' returns the number of bytes occupied by a variable or type OR the number of bytes occupied by an array.

So

1 == sizeof(char)
6 == sizeof ("Hello")  // Because of the trailing null
2 == sizeof(int)
int cards[][5] = {
                  {00,162,227,135,198} // card 1
                 };
210 == sizeof (cards)

So you line that says for(int x = 0; x < sizeof(cards); x++){ is happening 10 times, not the twice, not once.

Personally I would never use sizeof to measure the size of an array, but if you have to then you need to do this:

size = sizeof (cards) / sizeof (int)

This may not be your only issue, but I think you are using sizeof() wrongly. This 'function' returns the number of bytes occupied by a variable or type OR the number of bytes occupied by an array.

So

1 == sizeof(char)
6 == sizeof ("Hello")  // Because of the trailing null
2 == sizeof(int)
int cards[][5] = {
                  {00,162,227,135,198} // card 1
                 };
2 == sizeof (cards)

So you line that says for(int x = 0; x < sizeof(cards); x++){ is happening 10 times, not the twice, not once.

Personally I would never use sizeof to measure the size of an array, but if you have to then you need to do this:

size = sizeof (cards) / sizeof (int)

This may not be your only issue, but I think you are using sizeof() wrongly. This 'function' returns the number of bytes occupied by a variable or type OR the number of bytes occupied by an array.

So

1 == sizeof(char)
6 == sizeof ("Hello")  // Because of the trailing null
2 == sizeof(int)
int cards[][5] = {
                  {00,162,227,135,198} // card 1
                 };
10 == sizeof (cards)

So you line that says for(int x = 0; x < sizeof(cards); x++){ is happening 10 times, not once.

Personally I would never use sizeof to measure the size of an array, but if you have to then you need to do this:

size = sizeof (cards) / sizeof (int)
Source Link
Code Gorilla
  • 5.7k
  • 1
  • 17
  • 31

This may not be your only issue, but I think you are using sizeof() wrongly. This 'function' returns the number of bytes occupied by a variable or type OR the number of bytes occupied by an array.

So

1 == sizeof(char)
6 == sizeof ("Hello")  // Because of the trailing null
2 == sizeof(int)
int cards[][5] = {
                  {00,162,227,135,198} // card 1
                 };
2 == sizeof (cards)

So you line that says for(int x = 0; x < sizeof(cards); x++){ is happening 10 times, not the twice, not once.

Personally I would never use sizeof to measure the size of an array, but if you have to then you need to do this:

size = sizeof (cards) / sizeof (int)