# Pointer-Array Problems

#### varden

Joined Jul 11, 2016
38
Hi. I posted same problem a few days ago but still couldn't do it.I hope you can help. My problem is, I get data from bluetooth and can print it on 16x2 lcd. But I need to know lenght of coming data in order to complate my other project. Also if you know how I can write this data to SD card without knowing number of digits, it would be even better.(I use mikro C) This time I am posting whole code. I tried different things and this is final form.
Code:
char gelen;
char txt;
unsigned short k=0;

sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB0_bit;
sbit LCD_D7 at RB1_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB0_bit;
sbit LCD_D7_Direction at TRISB1_bit;

void main() {
CMCON  |= 7;

Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "Bluetooth-hc05");
delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
UART1_Init(2400);
Delay_ms(100);
for( ; ;)
{

while(gelen[k] != '\0'){
k++;

}

ShortToStr(k, txt);
Lcd_Chr_Cp(txt);

}
}
}
It says at while line, "pointer required."

#### joeyd999

Joined Jun 6, 2011
4,477
You have gelen defined as a character, not a character array. You will have the same problem with txt, I believe.

#### varden

Joined Jul 11, 2016
38
What it should be like? I tried as txt[16] and gelen[16] but outcome becomes meanless characters.

#### joeyd999

Joined Jun 6, 2011
4,477
What it should be like? I tried as txt[16] and gelen[16] but outcome becomes meanless characters.
For one thing, I think your for loop is not correct. As far as I can tell, your index k is never reset back to the beginning of the array.

Aside from that, since I use neither your compiler or libraries, I cannot help you further. Someone else will likely pop in here shortly.

#### ErnieM

Joined Apr 24, 2011
8,183
You are not reading the data properly. Assuming reading the data is all you need do...

You need two loops: outer loop loops until a zero is received to indicate the entire string is received, assuming the BT sends a traditional zero terminated string. Once you get that zero you can process the character array as you wish. Within this loop you need a single line loop to wait for the next character to be received.

Variable k gets reset at the top of the loop such when you exit the loop k now holds the character count.

How long the arrays need be depends on what the BT sends, you need look that up.

I don't use that compiler so see if they have an SD card library. Trust me, you do not want to write that code, you want a library.