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

String fprintf and fputc (fputc works, printf does not)

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



Joined: 19 Oct 2011
Posts: 31

View user's profile Send private message

String fprintf and fputc (fputc works, printf does not)
PostPosted: Sun May 20, 2012 9:47 am     Reply with quote

ok, with this code my output is
Code:

{0{}}

I expect the output to be
Code:
{8{Settings}}


which tells me the length of my string is 0, however if I uncomment the fputc statement, I get the expected data.

I have, for simplicity, taken out all of the error checking and other non essential code.

Compiler version is 4.132

Code:

while(BT_inchar != '\n')
   {
   while(!BT_Inchar_Ready)
      {
      }
      BT_Inchar_Ready = 0;
      RX_Buffer[RX_ctr] = BT_inchar;
      RX_ctr++;
   //   fputc(BT_inchar,prog);
   }
      fprintf(prog,"{%i{%s}}",strlen(RX_buffer), RX_Buffer);


here is my isr
Code:


#int_RDA
void  RDA_isr(void)
{
BT_Inchar = getc(BT);
BT_Inchar_Ready = 1;
}
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun May 20, 2012 5:47 pm     Reply with quote

Keep in mind using any string stuff in fprintf (or just printf) requires the string be NULL terminated.

Otherwise, the printf can run off into la-la land.

So when you get your string, before printing it, you need to make sure there's a zero at the end.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
mtsoule



Joined: 19 Oct 2011
Posts: 31

View user's profile Send private message

Got it!!
PostPosted: Mon May 21, 2012 4:39 am     Reply with quote

Thanks Ben, that was it! i ended up moving my "Buffer Filler" to the ISR (i hate putting it there) i like to go in to the ISR and get out. But i found it works best for my app.

Basically here is what i have now in the ISR
Code:

#int_RDA
void  RDA_isr(void)
{
BT_Inchar = getc(BT);

if((Packet == Packet_Count) && (BT_Inchar != '\r') && (BT_Inchar != '\n'))
   {
   RX_Buffer[RX_ctr] = BT_Inchar;
   RX_ctr++;
   RX_Buffer[RX_ctr] = 0x00;
   }

if(BT_Inchar == '\n')
   {
   BT_Inchar_Ready = 1;
   Packet_Count++;
   }


}


i do this so i can read a spific portion of the incomming stream, and i also want to throw away all the "LF's" and "CR's"
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