accessing a part of a char array
-
Im working in C++ w MFC. In my program i create a char that looks kinda like this: char data[11] = "1101110110"; and then later in the program i have a for which reads this binary data and does certain things depending on if its a 1 or 0: for ( short c=0; c<=10; c++ ) { if (data[c] == 1 ) { //do this } } But it doesn't work at all, the data[c] always seems to return 0 with the if.. any ideas? maybe theres a better way to store my binary data (which is actually a lot longer, like 64 chars) and then do things depending on 1 or 0? thanks! man ive gotten like loads of post errors now.. /Johannes
-
Im working in C++ w MFC. In my program i create a char that looks kinda like this: char data[11] = "1101110110"; and then later in the program i have a for which reads this binary data and does certain things depending on if its a 1 or 0: for ( short c=0; c<=10; c++ ) { if (data[c] == 1 ) { //do this } } But it doesn't work at all, the data[c] always seems to return 0 with the if.. any ideas? maybe theres a better way to store my binary data (which is actually a lot longer, like 64 chars) and then do things depending on 1 or 0? thanks! man ive gotten like loads of post errors now.. /Johannes
you are testing ascii values ie. '1' == 49 for this to work you can test if (data[c] == 49) or you can test if (data[c] == '1') Hope this helps :)
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
Im working in C++ w MFC. In my program i create a char that looks kinda like this: char data[11] = "1101110110"; and then later in the program i have a for which reads this binary data and does certain things depending on if its a 1 or 0: for ( short c=0; c<=10; c++ ) { if (data[c] == 1 ) { //do this } } But it doesn't work at all, the data[c] always seems to return 0 with the if.. any ideas? maybe theres a better way to store my binary data (which is actually a lot longer, like 64 chars) and then do things depending on 1 or 0? thanks! man ive gotten like loads of post errors now.. /Johannes
-
Im working in C++ w MFC. In my program i create a char that looks kinda like this: char data[11] = "1101110110"; and then later in the program i have a for which reads this binary data and does certain things depending on if its a 1 or 0: for ( short c=0; c<=10; c++ ) { if (data[c] == 1 ) { //do this } } But it doesn't work at all, the data[c] always seems to return 0 with the if.. any ideas? maybe theres a better way to store my binary data (which is actually a lot longer, like 64 chars) and then do things depending on 1 or 0? thanks! man ive gotten like loads of post errors now.. /Johannes
Johpoke wrote:
if (data[c] == 1 ) {
change this to
if (data[c] == '1' )
{
//do this
}Prasad Notifier using ATL | Operator new[],delete[][^]
-
Im working in C++ w MFC. In my program i create a char that looks kinda like this: char data[11] = "1101110110"; and then later in the program i have a for which reads this binary data and does certain things depending on if its a 1 or 0: for ( short c=0; c<=10; c++ ) { if (data[c] == 1 ) { //do this } } But it doesn't work at all, the data[c] always seems to return 0 with the if.. any ideas? maybe theres a better way to store my binary data (which is actually a lot longer, like 64 chars) and then do things depending on 1 or 0? thanks! man ive gotten like loads of post errors now.. /Johannes
Johpoke wrote:
char data[11] = "1101110110";
Are you really using
data
as a chars or as numbers? You can't directly compair a number to a char. If
data
is just an array of numbers and thats all its used for why not do an array of numbers then?
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
-
Im working in C++ w MFC. In my program i create a char that looks kinda like this: char data[11] = "1101110110"; and then later in the program i have a for which reads this binary data and does certain things depending on if its a 1 or 0: for ( short c=0; c<=10; c++ ) { if (data[c] == 1 ) { //do this } } But it doesn't work at all, the data[c] always seems to return 0 with the if.. any ideas? maybe theres a better way to store my binary data (which is actually a lot longer, like 64 chars) and then do things depending on 1 or 0? thanks! man ive gotten like loads of post errors now.. /Johannes