Sizeof function goes wrong !

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
renew
Posts: 28
Joined: 24 Nov 2016 13:56

Sizeof function goes wrong !

#1 Post by renew » 06 Aug 2021 04:57

Hi, people.
Very simple code here:

Code: Select all

Write_String_LCD(0, 0, "HELLO world !@#$%^&*()_+");

void Write_String_LCD(char xposition, char yposition, char *string){
    char i, s;
    s = sizeof(string));
    Set_Display_XYAddr(xposition, yposition);	// row, column
    //
    LCD_CS = 0;
    for(i=0; i<s; i++){
        Write_Char(string[i], 1);
    }
    LCD_CS = 1;
    return;
}
I see on the display only first 2 sighnes "HE". When I assign s = 24 I see all the string. What is wrong with the sizeof function ?
Is there other way how to know a size of the string ?

VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Re: Sizeof function goes wrong !

#2 Post by VCC » 06 Aug 2021 09:21

Hi,
Sizeof may return the size of a pointer in this case. See if you get better results with strlen function.
HTH :D

renew
Posts: 28
Joined: 24 Nov 2016 13:56

Re: Sizeof function goes wrong !

#3 Post by renew » 06 Aug 2021 16:59

Thanks, strlen works good.

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”