cancel
Showing results for 
Search instead for 
Did you mean: 

Sprintf effect on Send_text LwIP is going wrong

jendoubi saif ddine
Associate III
Posted on April 21, 2018 at 00:08

so this is my function that works fine when i add it to the script :

  • send_text(pAcceptedConnection, ' function drawChart() {var data = new google.visualization.DataTable();data.addColumn('string', 'Topping');data.addColumn('number', 'Slices');data.addRows([['Mushrooms', 3],['Onions', 2],['Olives', 1],['Zucchini', 4],['Pepperoni', 2]]);var options = {'title':'How Much Pizza I Ate Last Night','width':400,'height':300};var chart = new google.visualization.PieChart(document.getElementById('chart_div'));chart.draw(data, options);}');

but once i pass the inside message on Sprintf to make once of the values taken from a variable and do the same thing again like this : 

  • sprintf((char*) msggg1,' function drawChart() {var data = new google.visualization.DataTable();data.addColumn('string', 'Topping');data.addColumn('number', 'Slices');data.addRows([['Mushrooms', 3],['Onions', 2],['Olives', 1],['Zucchini', 4],['Pepperoni', %d]]);var options = {'title':'How Much Pizza I Ate Last Night','width':400,'height':300};var chart = new google.visualization.PieChart(document.getElementById('chart_div'));chart.draw(data, options);}',x);

    send_text(pAcceptedConnection,(const char*)msggg1);

it won't work 

this is the send function :

  1. static void

    send_text(struct netconn *conn, const char *text)

    {

    const char *src = text;

    u16_t len = 0;

    while (*src++ != '\0')

    len++;

    netconn_write(conn, text, len, NETCONN_COPY);

    }

if anyone can help please and thanks 

#lwip #stm32f7
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on April 21, 2018 at 00:40

Make sure your msggg1 character array is allocated with sufficient space behind it to hold the data you are generating.

sprintf() returns the string length

So smarter implementation looks like

netconn_write(pAcceptedConnection, msggg1, sprintf(msggg1,'..',..), NETCONN_COPY);

sscanf/sprintf may also have stack utilization, check it is sufficient

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3
Posted on April 21, 2018 at 00:40

Make sure your msggg1 character array is allocated with sufficient space behind it to hold the data you are generating.

sprintf() returns the string length

So smarter implementation looks like

netconn_write(pAcceptedConnection, msggg1, sprintf(msggg1,'..',..), NETCONN_COPY);

sscanf/sprintf may also have stack utilization, check it is sufficient

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 21, 2018 at 00:58

Thanks for responding as usual sir, 

sadly that didn't work .. i even tryed to change sending function but it didn't work

Posted on April 21, 2018 at 01:07

sorry i checked again, thank you very much ! man u r a savior as usual !