|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Copy from string to string |
Posted: Thu Aug 06, 2009 4:23 pm |
|
|
Is this a valid operation?
The string array is defined like this
Code: |
byte db_filename[const_NODB][15];
|
here is the actual copy
ftdi_setting_file has been confirmed to be a valid string with null terminator.
Code: |
strncpy(db_filename[0][0],ftdi_setting_file,14);
fprintf(con,"db filename = %s\n\r",db_filename[0][0]);
|
Thanks guys |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 06, 2009 11:36 pm |
|
|
Post a little test program that loads the array with a string, copies it,
and then displays the array that it was copied to. Here's an example
of a test program. It can be run in MPLAB simulator, with "UART1"
selected for output, so the text appears in the Output window. The
program can be tested entirely in MPLAB simulator. Make it easy for us
to work on your problem. Provide a test program. Also give your
compiler version.
Code: |
#include <16F877.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//==============================
void main()
{
char buffer[] = {"Hello World\n\r"};
printf(buffer);
while(1);
} |
See this post for instructions on how to use the "UART1" feature of the
MPLAB simulator to display serial output in the MPLAB Output Window:
http://www.ccsinfo.com/forum/viewtopic.php?t=23408&start=1 |
|
|
n-squared
Joined: 03 Oct 2006 Posts: 99
|
|
Posted: Fri Aug 07, 2009 1:52 am |
|
|
Dear guest,
A pointer to string can either be the name of the string or &string[0].
You have an array of strings, which means you cannot specify
string[0][0] at the address.
Your lines should be as follows:
Code: |
strncpy(&db_filename[0][0],ftdi_setting_file,14);
fprintf(con,"db filename = %s\n\r",&db_filename[0][0]);
|
or
Code: |
strncpy(db_filename[0],ftdi_setting_file,14);
fprintf(con,"db filename = %s\n\r",db_filename[0]);
|
I hope this helps _________________ Every solution has a problem. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Fri Aug 07, 2009 2:05 am |
|
|
Also as ftdi_setting_file is a null terminated string you can just use strcpy instead of strncpy.
Code: |
strncpy(&db_filename[0][0],ftdi_setting_file,14);
|
Change to
Code: |
strcpy(db_filename[0], ftdi_setting_file);
|
|
|
|
|
|
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
|