CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pointer to string problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
proggy
Guest







Pointer to string problem
PostPosted: Mon Jul 14, 2003 12:00 pm     Reply with quote

I'm trying to pass a string to my LCDPrint function. LCDPrint should print the offsetted characters (string) to the LCD screen, but it doesn't work. Can anyone explain why this does not work with the CCS compiler or if there is another way around this?

void LCDPrint(char *pch)
{
while(*pch)
{
AutoOut(*pch - 0x20); //output offset character
pch++; //point to next character
}
}

I'm using version 3.168.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515961
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Pointer to string problem
PostPosted: Mon Jul 14, 2003 12:56 pm     Reply with quote

:=I'm trying to pass a string to my LCDPrint function. LCDPrint should print the offsetted characters (string) to the LCD screen, but it doesn't work. Can anyone explain why this does not work with the CCS compiler or if there is another way around this?
:=
:=void LCDPrint(char *pch)
:={
:= while(*pch)
:= {
:= AutoOut(*pch - 0x20); //output offset character
:= pch++; //point to next character
:= }
:=}
:=
:=I'm using version 3.168.
-----------------------------------------------

I don't have an LCD on my test board, currently, so I
just directed the output to putc() instead, but this
test program worked OK with PCM vs. 3.168.

Because you're subtracting 0x20 from each char, I had
to use lower case chars and the @ symbol, in order to
get some readable output on my terminal window.

It displays: "HELLO WORLD"

#include "c:\Program Files\Picc\Devices\16F877.H"
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)

void LCDPrint(char *pch);

void AutoOut(char value);


//=============================================================
void main()
{
char buffer[20];

strcpy(buffer, "hello@world");
LCDPrint(buffer);


while(1);
}

//=============================================================

void LCDPrint(char *pch)
{
while(*pch)
{

AutoOut(*pch - 0x20); //output offset character
pch++; //point to next character
}
}


void AutoOut(char value)
{
putc(value);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515965
proggy
Guest







Re: Pointer to string problem
PostPosted: Mon Jul 14, 2003 1:46 pm     Reply with quote

Instead of copying the string into buffer, couldn't you use the function itself?

For example:
LCDPrint("testing display");



:=-----------------------------------------------
:=
:=I don't have an LCD on my test board, currently, so I
:=just directed the output to putc() instead, but this
:=test program worked OK with PCM vs. 3.168.
:=
:=Because you're subtracting 0x20 from each char, I had
:=to use lower case chars and the @ symbol, in order to
:=get some readable output on my terminal window.
:=
:=It displays: "HELLO WORLD"
:=
:=#include "c:\Program Files\Picc\Devices\16F877.H"
:=#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
:=#use delay(clock = 8000000)
:=#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
:=
:=void LCDPrint(char *pch);
:=
:=void AutoOut(char value);
:=
:=
:=//=============================================================
:=void main()
:={
:=char buffer[20];
:=
:=strcpy(buffer, "hello@world");
:=LCDPrint(buffer);
:=
:=
:=while(1);
:=}
:=
:=//=============================================================
:=
:=void LCDPrint(char *pch)
:={
:= while(*pch)
:= {
:=
:= AutoOut(*pch - 0x20); //output offset character
:= pch++; //point to next character
:= }
:=}
:=
:=
:=void AutoOut(char value)
:={
:=putc(value);
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515968
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Pointer to string problem
PostPosted: Mon Jul 14, 2003 2:11 pm     Reply with quote

:=Instead of copying the string into buffer, couldn't you use the function itself?
:=
:=For example:
:=LCDPrint("testing display");
--------------------------------------------------------

No, because CCS doesn't support pointers to constant strings.

However, you can re-write your code to do it this way:

<PRE>
#include "c:\Program Files\Picc\Devices\16F877.H"
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
<BR>
void LCDPrint(char c);
void AutoOut(char value);
<BR>
char const message1[] = {"hello@world"};
<BR>
//=============================================================
void main()
{
<BR>
LCDPrint(message1);
<BR>
while(1);
}
<BR>
//=============================================================
<BR>
void LCDPrint(char c)
{
AutoOut(c - 0x20); //output offset character
}
<BR>
<BR>
void AutoOut(char value)
{
putc(value);
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515971
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group