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

Printf not working as expected [Solved]

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



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

Printf not working as expected [Solved]
PostPosted: Wed Sep 23, 2020 9:06 am     Reply with quote

I'm trying to print in a string but I see no changes after printf
What I'm doing wrong?



Code:

char IndexBufferCmdMain;
#define BufferCmdMainSize 15
char BufferCmdMain[BufferCmdMainSize][12];

#define AlarmRxBufferSize 16
char AlarmRxBuffer[AlarmRxBufferSize];//128bits
unsigned int16 EventoCid;

#define Part 0x09
#define User 0x0A

printf(BufferCmdMain[IndexBufferCmdMain][0],"%4LX A%1X A%2X\r\n",EventoCid,AlarmRxBuffer[Part],AlarmRxBuffer[User]);

_________________
Electric Blue


Last edited by E_Blue on Wed Sep 23, 2020 1:28 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 9:15 am     Reply with quote

If you want to print to a buffer, you should use sprintf, not printf.
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 9:24 am     Reply with quote

You need to post a real small program that comments what is expected and shows us what IS printed.

If you're trying to fill 'BufferCmdMain[IndexBufferCmdMain][0]' with 'EventoCid,AlarmRxBuffer[Part],AlarmRxBuffer[User])' data then you need to use the SPRINTF() function.
I'm thinking that's what you want to do. Look for Sprintf() in the manual, there is a small example listed.

Jay
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 9:25 am     Reply with quote

Changed
Code:
printf(BufferCmdMain[IndexBufferCmdMain][0],"%4LX A%1X A%2X\r\n",EventoCid,AlarmRxBuffer[Part],AlarmRxBuffer[User]);


to
Code:
sprintf(BufferCmdMain[IndexBufferCmdMain][0],"%4LX A%1X A%2X\r\n",EventoCid,AlarmRxBuffer[Part],AlarmRxBuffer[User]);


doesn't work

Changed to

Code:
sprintf(BufferCmdMain[IndexBufferCmdMain],"%4LX A%1X A%2X\r\n",EventoCid,AlarmRxBuffer[Part],AlarmRxBuffer[User]);

and worked ok.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Wed Sep 23, 2020 11:34 am     Reply with quote

sprintf, needs to be given the address where it is to put the data.

BufferCmdMain[IndexBufferCmdMain][0]

Is not an address.

to put the data into BufferCmdMain, you would just use
BufferCmdMain. If you want to put it to an offset location in this
buffer, then you need to use &, and the index, so:

&BufferCmdMain[IndexBufferCmdMain][0]
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