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 CCS Technical Support

strcpy()

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



Joined: 18 Nov 2013
Posts: 160

View user's profile Send private message

strcpy()
PostPosted: Mon Sep 21, 2015 2:37 pm     Reply with quote

I am using CCS compiler v5.049 with an 18F8722 cpu.

I've used strcpy() alot over the years and have never seen a problem like this.
Code:

   char tmp[9];
   byte tmp2[9];
   strcpy( tmp, "INITDONE" );
   strcpy( (char*)tmp2, "INITDONE" );


After the first strcpy() runs, array tmp will have some number of non-ascii
characters in it. The number of non-ascii characters changes based on where in
the program that code is located. But the non-ascii chars are always 0xFE. I know
you might think that the array is being stomped on, but that is not the case.
I break the program at strcpy() and step over it, then examine the contents
with the debugger.

After the second strcpy() runs, the value of tmp2 is always correct.

Steve
SeeCwriter



Joined: 18 Nov 2013
Posts: 160

View user's profile Send private message

PostPosted: Mon Sep 21, 2015 3:30 pm     Reply with quote

Correction: the processor used is the 12LF1552, NOT the 18F8722.
SeeCwriter



Joined: 18 Nov 2013
Posts: 160

View user's profile Send private message

PostPosted: Mon Sep 21, 2015 4:34 pm     Reply with quote

Correction #2: the pic really is the 18F8722. Can't run the debugger on a 12LF1552. Juggling too many projects. Oiy vey!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 21, 2015 6:09 pm     Reply with quote

Now that we're back to something that I can test in MPLAB vs. 8.92 simulator...

I made this test program and ran it in the simulator and it seems to work
just fine. Here are the results in the Output Window:
Quote:

tmp = INITDONE
tmp2 = INITDONE

Code:
#include <18F8722.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

//===========================
void main()
{
char tmp[9];
byte tmp2[9];

strcpy( tmp, "INITDONE" );
strcpy( (char*)tmp2, "INITDONE" );
 
printf("tmp = %s \r", tmp);
printf("tmp2 = %s \r", tmp);


while(TRUE);   
}
SeeCwriter



Joined: 18 Nov 2013
Posts: 160

View user's profile Send private message

PostPosted: Tue Sep 22, 2015 8:27 am     Reply with quote

I don't know what to say. Not only doesn't strcpy() work, but memcpy() doesn't work either. And when I said that declaring 'tmp' as a byte array worked, I was wrong. It only worked once.
I am reduced to do the following:

Code:

char tmp[9];
tmp[0]='I';tmp[1]='N';tmp[2]='I';tmp[3]='T';tmp[4]='D';tmp[5]='O';tmp[6]='N';tmp[7]='E';tmp[8]=NUL;


Crude, but it works.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 22, 2015 3:03 pm     Reply with quote

You shouldn't have to do that. Either you have a damaged compiler
or you're doing something else that is not shown. You shouldn't use
a damaged compiler to continue a project. At a minimum, re-install
the compiler.

What happens if you do my test ? Compile and run my test program
in MPLAB simulator. Does it work ?

I'm trying to think of what else could possibly cause your problem.
Just wondering, but do you have old CCS include files, leftover from
some previous version of the compiler, sitting in your project directory ?
Or, have you been using CCS's "version switching" program to switch
between different versions of the compiler ? You're doing something.
I just don't know what.
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Tue Sep 22, 2015 4:46 pm     Reply with quote

I've had to do the same crude thing in a recent project because 4.141 wasn't handling strings.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 22, 2015 5:20 pm     Reply with quote

There are other ways to initialize strings at compile time. For me, with
vs. 5.049, the following code works in MPLAB vs. 8.92 simulator.
It displays this in the Output Window:
Quote:
INITDONE

Test program:
Code:

#include <18F4620.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

//============================
void main()
{
char tmp[9] = "INITDONE";

printf("%s", tmp);


while(TRUE);
}

 

My question for the O.P. is, does any of this stuff work for you ?
My two examples ?
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