Using floats with sprintf() in embedded C

后端 未结 13 1858
别跟我提以往
别跟我提以往 2020-12-24 06:35

Guys, I want to know if float variables can be used in sprintf() function.

Like, if we write:

sprintf(str,\"adc_read = %d \         


        
13条回答
  •  爱一瞬间的悲伤
    2020-12-24 06:59

    Isn't something like this really easier:

    #include 
    #include 
    #include 
    
    char str[10];
    float adc_read = 678.0123;
    
    dtostrf( adc_read, 3, 4, temp );
    sprintf(str,"adc_read = %10s \n", temp);
    printf(temp);
    

提交回复
热议问题