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

What is the number of parameters allowed to use sprintf ()?

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



Joined: 18 Feb 2008
Posts: 48

View user's profile Send private message

What is the number of parameters allowed to use sprintf ()?
PostPosted: Sat Dec 10, 2011 4:55 pm     Reply with quote

What is the number of parameters allowed to use sprintf ()?
In my application I need to send 50 byte parameters in a string, but when I add more than 28 parameters the compiler gives the error:
Too many parameters
does not compile the program.
That may be the problem?
Is there any place where I can do this I need to change some parameters of the compiler?

Thank you for your help.
_________________
MGLSOFT
temtronic



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

View user's profile Send private message

PostPosted: Sat Dec 10, 2011 8:24 pm     Reply with quote

I've run into that as well, I just split the print into 3 or 4 groups of parameters and it's worked fin for the past year or so.
mglsoft



Joined: 18 Feb 2008
Posts: 48

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 11:25 am     Reply with quote

Thanks for answering.
My problem is that shipping is a TCP / IP and I have that division made by group of parameters, and all should be able to send at least 44 different parameters, if I have to subdivide will be at least 16 messages instead of 8 ...
_________________
MGLSOFT
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 11:46 am     Reply with quote

Why not append them into a string then send the string all at once?
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 11:51 am     Reply with quote

No.
Subdividing the printf, doesn't mean you have to increase the number of messages.
All you do is either send the separate printf operations to a buffer, and only initiate the transmission once the buffer is complete, or if using a printf to your own function, have a separate flag called something like 'end_of_message', and only set this once you have sent all the parameters you want.
Separate printf's don't mean separate messages.
Think about this for example:
Code:

printf(lcd_putc,"\f");
printf(lcd_putc,"First ");
printf(lcd_putc,"Second");

Gives:
Code:

First Second

on the top left corner of the LCD, with the characters arriving as fast as the LCD can take them.

Best Wishes
temtronic



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

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 11:59 am     Reply with quote

Another example for you...

Here's how I store data on the Vinculum as a CSV formatted record.
Code:
void usbfd_save_data(){
fprintf(usbfd,"WRF %C%C%C%C\r%C%C,%C%C,%C%C,%C%C,%C%C,%C%C,%C%C%C%C,%C%C%C%C,%C,%C%C%C\r",zro,zro,zro,0x21
,str_yer[0],str_yer[1]
,str_mth[0],str_mth[1]
,str_day[0],str_day[1]
,str_hrs[0],str_hrs[1]
,str_min[0],str_min[1]
,str_sec[0],str_sec[1]
,str_t1[0],str_t1[1],str_t1[2],str_t1[3]
,str_t2[0],str_t2[1],str_t2[2],str_t2[3]
,str_s1[0],str_s1[1]
,acr,alf
);
}


It allows a PC with Excel to automatically import the data into a spreadsheet.
mglsoft



Joined: 18 Feb 2008
Posts: 48

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 12:18 pm     Reply with quote

I think I have understood what I want and need to do.
I'll paste the code so industry can better help:

Code:
sprintf(str,"0101 : %02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U,%02U ",
      SxM_1a8[0],SxM_1a8[1],SxM_1a8[2],SxM_1a8[3],SxM_1a8[4],SxM_1a8[5],SxM_1a8[6],SxM_1a8[7],
      SxM_9a16[0],SxM_9a16[1],SxM_9a16[2],SxM_9a16[3],SxM_9a16[4],SxM_9a16[5],SxM_9a16[6],SxM_9a16[7],
      SxM_17a24[0],SxM_17a24[1],SxM_17a24[2],SxM_17a24[3],SxM_17a24[4],SxM_17a24[5],SxM_17a24[6],SxM_17a24[7],
      SxM_25a32[0],SxM_25a32[1],SxM_25a32[2],SxM_25a32[3]);  /*,SxM_25a32[4],SxM_25a32[5],SxM_25a32[6],SxM_25a32[7],
      SxM_33a40[0],SxM_33a40[1],SxM_33a40[2],SxM_33a40[3],SxM_33a40[4],SxM_33a40[5],SxM_33a40[6],SxM_33a40[7],
      SxM_41a48[0],SxM_41a48[1],SxM_41a48[2],SxM_41a48[3]);  ,%03U,%03U,%03U,%03U,%03U,%03U,%03U,%03U,%03U,
      %03U,%03U,%03U,%03U,%03U,%03U,%03U,%03U*/

      TCPPutArray(socket,str,strlen(str));
      TCPFlush(socket);




As you will see this discussed much of the parameters that need to send TCP / IP.
Not a printf (), but a sprintf ().
_________________
MGLSOFT
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sun Dec 11, 2011 2:38 pm     Reply with quote

Makes it even easier.
Sprintf, just puts the data into a string, starting at the address given. Just send a few values, then use strlen to find the length of the first part, and add the value returned to the address you use for the second call. Repeat until the whole string is built.
Very standard programming.

Best Wishes
mglsoft



Joined: 18 Feb 2008
Posts: 48

View user's profile Send private message

PostPosted: Mon Dec 12, 2011 8:09 pm     Reply with quote

OK, I'll try as you say, then I will put the experience here.
Thank you.
_________________
MGLSOFT
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Dec 13, 2011 5:05 am     Reply with quote

Design hint: instead of using strlen to determine the length of the string created by sprintf, you can use the return value of sprintf.

something like:
Code:
char buffer[500];
char *buf_pointer;

buf_pointer = &buffer[0];

buf_pointer += sprintf(buf_pointer, "my very long formatting string here");
buf_pointer += sprintf(buf_pointer, "my second formatting string here");
mglsoft



Joined: 18 Feb 2008
Posts: 48

View user's profile Send private message

PostPosted: Thu Dec 15, 2011 7:05 pm     Reply with quote

ckielstra:
Thank you very much for your idea of using pointers to implement and finish it works perfect!
I'll get what are the limits, to know and take them into account.
Thanks to other forum participants for your interest in helping me.
I'll be here to help in my humble knowledge that will allow me to do so.
_________________
MGLSOFT
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