Pointer-Array Problems

Thread Starter


Joined Jul 11, 2016
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.
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() {
ADCON1 |= 0X0F;
CMCON  |= 7;

Lcd_Out(1, 1, "Bluetooth-hc05");
for( ; ;)
if (UART1_Data_Ready()) {
gelen = UART1_Read();

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


ShortToStr(k, txt);

It says at while line, "pointer required."

Thread Starter


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


Joined Jun 6, 2011
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.


Joined Apr 24, 2011
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.

Thread Starter


Joined Jul 11, 2016
Oh thanks, you are right I forget about k doesn't reset. I will try to fix it.
And I am still beginner I couldn't even dare to use SD card without library :D But library needs you to enter how many character you want to write. If I say something bigger it loops until fill it. So this is my main problem.

Also my teacher told us mikro C is very populer compiler and that is why we chose it. But know I started to doubt about it :D