![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Burt Poppenga Guest
|
Help with strcpy |
Posted: Wed Mar 26, 2003 9:34 pm |
|
|
Hello,
I must be having a brain malfunction. I can't see why the following sample program does not work (PCH 3.148):
#include <18F452.h>
#fuses XT,NOWDT,PUT,NOLVP,NOPROTECT
#device *=16
#device ADC=10
#use delay(clock=4000000, RESTART_WDT) // 4 MHz clock
#use rs232(baud=19200, parity=N, bits=8, xmit=PIN_C6, rcv=PIN_C7, errors)
#include <string.h>
void rom_fmtstr_to_ram(char *destStr)
{
printf("rom_fmtstr_to_ram start: \%s\n\r", destStr);
strcpy(destStr, "Carp");
printf("rom_fmtstr_to_ram end: \%s\n\r", destStr);
}
// The test.
main()
{
char bString[10];
// Put something into the string
strcpy(bString, "Hello");
// Re-write the string
rom_fmtstr_to_ram(bString);
// Display the results (should be different)
printf("Main Done: \%s\n\r", bString);
// Don't fall off into the deep SLEEP
while(1);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13115 |
|
![](templates/subSilver/images/spacer.gif) |
Ron Guest
|
Re: Help with strcpy |
Posted: Thu Mar 27, 2003 6:13 am |
|
|
Code looks ok to me.
What exactly is not working?
:=Hello,
:=
:=I must be having a brain malfunction. I can't see why the following sample program does not work (PCH 3.148):
:=
:=#include <18F452.h>
:=
:=#fuses XT,NOWDT,PUT,NOLVP,NOPROTECT
:=#device *=16
:=#device ADC=10
:=#use delay(clock=4000000, RESTART_WDT) // 4 MHz clock
:=#use rs232(baud=19200, parity=N, bits=8, xmit=PIN_C6, rcv=PIN_C7, errors)
:=
:=#include <string.h>
:=
:=void rom_fmtstr_to_ram(char *destStr)
:={
:= printf("rom_fmtstr_to_ram start: \%s\n\r", destStr);
:= strcpy(destStr, "Carp");
:= printf("rom_fmtstr_to_ram end: \%s\n\r", destStr);
:=}
:=
:=// The test.
:=main()
:={
:= char bString[10];
:=
:= // Put something into the string
:= strcpy(bString, "Hello");
:=
:= // Re-write the string
:= rom_fmtstr_to_ram(bString);
:=
:= // Display the results (should be different)
:= printf("Main Done: \%s\n\r", bString);
:=
:= // Don't fall off into the deep SLEEP
:= while(1);
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13132 |
|
![](templates/subSilver/images/spacer.gif) |
Burt Poppenga Guest
|
Re: Help with strcpy |
Posted: Thu Mar 27, 2003 8:42 am |
|
|
The output of the routine is:
rom_fmtstr_to_ram start: Hello
rom_fmtstr_to_ram end:
Main Done: Hello
I expected something more like:
rom_fmtstr_to_ram start: Hello
rom_fmtstr_to_ram end: Carp
Main Done: Carp
___________________________
This message was ported from CCS's old forum
Original Post ID: 13134 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Help with strcpy |
Posted: Thu Mar 27, 2003 12:59 pm |
|
|
:=I must be having a brain malfunction. I can't see why the following sample program does not work (PCH 3.148):
:=
:=void rom_fmtstr_to_ram(char *destStr)
:={
:= printf("rom_fmtstr_to_ram start: \%s\n\r", destStr);
:= strcpy(destStr, "Carp");
:= printf("rom_fmtstr_to_ram end: \%s\n\r", destStr);
:=}
---------------------------------------------------------
I don't have PCH, but PCM 3.149 with a 16F877 shows the same
behavior. I think it's a bug in strcpy(). It doesn't seem
to be able handle a passed array pointer. It uses ram
locations for temporary counters, that are part of the
destination array. If you change the code so that the
array is in the local routine, then strcpy works OK.
void rom_fmtstr_to_ram(char *destStr)
{
char tempStr[10];
printf("rom_fmtstr_to_ram start: \%s\n\r", destStr);
strcpy(tempStr, "Carp");
printf("rom_fmtstr_to_ram end: \%s\n\r", tempStr);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13155 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|