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

copy string to another within limited chars

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



Joined: 05 Jan 2006
Posts: 105

View user's profile Send private message

copy string to another within limited chars
PostPosted: Sun Jan 08, 2006 8:48 am     Reply with quote

hi all
how can i copy some char(limited by two chars) from on string to another
i try to do this
Code:

#include <16f874.h>
#include "lcd_kbd1.c"
#include <string.h>
#fuses XT,NOWDT,NOLVP
#use delay(clock=4000000)    //one instruction=1us
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS)

static char RX[20] ,MX[20] ,string1[20], string2[20],S1[10],S2[10];
static int1 jj;
static int8 i,n;
static int8 rank1,rank2,r;



#int_rda
void serial_isr()  {


RX[i++]=getch();
//strcpy(string1,RX);
jj=1;
}



void main()   {
   jj=0;
   strcpy(S1,"C");
   strcpy(S2,"H");
   LCD_Init ( );
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);

   if(jj==1) {
   strcpy(string1,RX);
   n=0;
   rank1=strcspn(string1, S1); //   Count of initial chars in string1 not in s2
   rank2=strcspn(string1, S2); //   Count of initial chars in string1 not in s2
   LCD_PutCmd ( CLEAR_DISP );
   LCD_SetPosition ( LINE_16_1);
   printf(LCD_PutChar,string1);
    delay_ms(2000);
   LCD_PutCmd ( CLEAR_DISP );
   LCD_SetPosition ( LINE_16_1);
   printf(LCD_PutChar,"rank1 is%u",rank1);

   LCD_SetPosition ( LINE_16_2);
   printf(LCD_PutChar,"rank2 is%u",rank2);
   delay_ms(2000);
//   r=rank2-1;
//   LCD_PutCmd ( CLEAR_DISP );
//   LCD_SetPosition ( LINE_16_1);
//   printf(LCD_PutChar,"ris%u",r);
   for(i=(rank1+2);i<rank2;i++) {
   MX[n]=RX[i];
   n++;
      }//for
   strcpy(string2,MX);   
   LCD_PutCmd ( CLEAR_DISP );
   LCD_SetPosition ( LINE_16_1);
   printf(LCD_PutChar,"string2",string2);

   jj=0;
   i=0;
   }//if


}//MAIN


its give me
ABCDEFGHIJKLMNOP
rank1=2,
rank2=7,
string2=

nothing in string2
also i try to do this

Code:

   for(i=(rank1+2);i<rank2;i++) {
   string2[n]=string1[i];
   n++;
      }//for

and give me the same.

note:its supposed to recieve ABCDEFGHIJKLMNOP from another pic
so whats wrong???????
thanx alot
hadeelqasaimeh



Joined: 05 Jan 2006
Posts: 105

View user's profile Send private message

PostPosted: Sun Jan 08, 2006 9:00 am     Reply with quote

oh....yes i get it
im sorry , if orget to do this

Code:
  printf(LCD_PutChar,"string2 is %s",string2);


its working now!!! but why do string 1 appear on lcd without doing this??
this is strange Rolling Eyes
VanHauser



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

PostPosted: Sun Jan 08, 2006 1:21 pm     Reply with quote

string1 appeared because there is no format specifier string like "string1 is %s". When you specify only a string, printf is wise enough to notice you are trying to print that string. I hope I made myself clear.

Keep in mind that you can print a single string with LCD_PutChar(string)
or LCD_PutChar("this is some text").
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