Muhammed Yıldız Muhammed Yıldız - 2 months ago 21
C++ Question

How to read elements of array using c++?

I am taking datas from serial port using these commands Program screenshot, and this is my data ::02::03::98::00::07::20::16::09::29::16::19::45::C0::00::00::00

I can see coming datas using these commands;

for(sa=0;sa<15;sa++){
printf("::%0.2X",buf[sa]);
}


but i don't use elements of buf[] array in any equations,for example i want to use buf[2] in a equation like below.

if(buf[2]==02){
cout<<"Equality"<<endl;
}


Can anybody help me ?

enter image description here

dd2 dd2
Answer

You might want to compare them in hexadecimal format.

if( buf[2]==0x02){
      cout<<"Equality"<<endl;
}
Comments