Basic char, int and ASCI with 'if' function - simple question

Hi
I've got a little problem with this.
It is a program that reads messages from the sensors of temperature and wetness in a room. In fact the data is stored in an array kom[][].
My problem is how to construct the function --if--
I would it to check if the fourth letter is H or T
egzample:
$P1HUM = 39.22 --> the 4th letter is H, it is the wetness

It's rather simple but I mess with it the second day...



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
	{

	char kom[8][20] =  {"$P1HUM = 39.22" ,"$P2HUM = 65.1",
					    "$P2TEMP = 26.19" ,"$P3HUM = 85.9",
					    "$P2HUM = 68.23" ,"$P1TEMP = 24.33",
					    "$P3TEMP = 29.5" ,"$P3TEMP = 28.74"}; 

	for(int i=0;i<1;i++)											//komunikaty
	{	
		for(int j=0;j<16;j++)
		{	
			if(kom[i][4]=='T')       // !Here is my problem!   asci T=84		 H=72		
			{
				printf("Point nr. %c, temperature measure, level %d%d.%d%d\n",kom[i][3],kom[i][11],kom[i][12],kom[i][14],kom[i][15]);
				 				 
				 
			}
			else if(kom[i][4]==72)								
			{
				printf("Point nr. %c, wetness measure, level %d%d.%d%d\n",kom[i][3],kom[i][10],kom[i][11],kom[i][13],kom[i][14]);
				 		 
				 
			}
			else
			{
				//int a = 0;
				printf("error reading \n");
			}	
		}
	}

	return 0;}
 
Last edited on
Fouth letter has index of 3. Count it yourself: 0-1-2-3.
So, change kom[ i ][4 3]
Last edited on
Topic archived. No new replies allowed.