Searching \ for ' Problem with strings with hi-tech' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/index.htm?key=problem+with+strings
Search entire site for: 'Problem with strings with hi-tech'.

No exact or substring matches. trying for part
PICList Thread
'[PICLIST] Problem with strings with hi-tech'
2001\10\25@161610 by Microchip

flavicon
face
I want to declare an array of strings like :

const unsigned char Str1 [2][5] = {"Hello", "Bye  "};

My problem is the compilator doesn't put the null caracter (\0) at end of each string.

I also try :

const unsigned char Str1 [2][6] = {"Hello", "Bye  "};

but it also doesn't work.

Please can someone help me?

Jonathan Poulin
Technicien en électronique et programmeur
Nova Biomatique Inc
spam_OUTjpoulinTakeThisOuTspamnovabiomatique.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\10\25@163930 by Pfaff, John

flavicon
face
Try this:

const unsigned char Str1 [2][5] = {"Hello\0", "Bye  \0"};

That should put an explicit NULL at the end of each string.

Microchip wrote:
{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\10\25@165937 by Paul Hutchinson

flavicon
face
That seems odd, I thought ANSI compliant C's automatically appended the
null.

Maybe manually adding the terminating null as an escape sequence to each
string will work.

Like this:

const unsigned char Str1 [2][6] = {"Hello\x000", "Bye  \x000"};

Paul

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\10\25@180631 by Dipperstein, Michael

face picon face
> From: Microchip [.....microchipKILLspamspam.....novabiomatique.com]
>
> I want to declare an array of strings like :
>
> const unsigned char Str1 [2][5] = {"Hello", "Bye  "};
>
> My problem is the compilator doesn't put the null caracter
> (\0) at end of each string.
>
> I also try :
>
> const unsigned char Str1 [2][6] = {"Hello", "Bye  "};
>
> but it also doesn't work.
>
> Please can someone help me?

Using PIC-C 7.87PL2, I wrote the following code:

#include <pic.h>

const unsigned char Str1 [2][6] = {"Hello", "Bye  "};

void main(void)
{
   int i;

   i = (Str1[2][3] == 'q');
   return;
}

and looking at the listing, I see:

   18  0009                     _Str1
   19  0009  3448                      retlw   (((048h)))
   20  000A  3465                      retlw   (((065h)))
   21  000B  346C                      retlw   (((06Ch)))
   22  000C  346C                      retlw   (((06Ch)))
   23  000D  346F                      retlw   (((06Fh)))
   24  000E  3400                      retlw   0
   25  000F  3442                      retlw   (((042h)))
   26  0010  3479                      retlw   (((079h)))
   27  0011  3465                      retlw   (((065h)))
   28  0012  3420                      retlw   (((020h)))
   29  0013  3420                      retlw   (((020h)))
   30  0014  3400                      retlw   0

The NULLs are being allocated at the end of each string as (0x000E and 0x0014)
as I would expect.

-Mike

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\10\25@182343 by Byron A Jeff
face picon face
On Thu, Oct 25, 2001 at 04:06:16PM -0400, Microchip wrote:
> I want to declare an array of strings like :
>
> const unsigned char Str1 [2][5] = {"Hello", "Bye  "};
>
> My problem is the compilator doesn't put the null caracter (\0) at end of each string.
>

On GCC it truncates.

> I also try :
>
> const unsigned char Str1 [2][6] = {"Hello", "Bye  "};
>
> but it also doesn't work.

It worked here.


>
> Please can someone help me?

Why not

const unsigned char *Str1[2] = {"Hello","Bye   "};

?

BAJ

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\10\25@192755 by Ned Konz

flavicon
face
On Thursday 25 October 2001 01:06 pm, Microchip wrote:
> I want to declare an array of strings like :
>
> const unsigned char Str1 [2][5] = {"Hello", "Bye  "};
>
> My problem is the compilator doesn't put the null caracter (\0) at end of
> each string.

That's because there are 5 characters in "Hello" and you didn't give it any
room to put the NUL in .

This suggestion won't work for the same reason:

> Try this:
>
> const unsigned char Str1 [2][5] = {"Hello\0", "Bye  \0"};
>
> That should put an explicit NULL at the end of each string.

The (const unsigned char str1[2][6]) should give you enough room as well as
give you the NUL chars.

But note that this will reserve space for 12 bytes; if you have a
larger/sparser array than this it might make sense to have an array of char*
(of course, the generated code may be somewhat slower because the PIC is bad
at pointers):

const unsigned char  * const Str1[2] = { "Hello", "Bye" };

--
Ned Konz
currently: Stanwood, WA
email:     EraseMEnedspam_OUTspamTakeThisOuTbike-nomad.com
homepage:  http://bike-nomad.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\10\25@211647 by Rodrigo Valladares P.

picon face
Hi,

with str1[2][5]

in main:

you can access at str[0][...] or str[1], not str[2], this is out of the
array. arrays begin at 0 and go to size-1.


char x[10];

for(i=0; i<10; i++)
  { ...  }


----- Mensaje original -----
De: "Dipperstein, Michael" <mdippersspamspam_OUTHARRIS.COM>
Para: <@spam@PICLISTKILLspamspamMITVMA.MIT.EDU>
Enviado: Jueves 25 de Octubre de 2001 6:02 PM
Asunto: Re: Problem with strings with hi-tech


-----8<-------
{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...