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

Copy from string to string

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








Copy from string to string
PostPosted: Thu Aug 06, 2009 4:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 06, 2009 11:36 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Aug 07, 2009 1:52 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 07, 2009 2:05 am     Reply with quote

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);
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