How to concatenate a string and float in C

1 Answer

0 votes
#include <stdio.h>

int main() {
    float f = 13.5;
    char s[32] = "c programming";
    char buf[64] = "";

    snprintf(buf, 64, "%s - %.2f", s, f);
    printf("%s\n", buf);

    return 0;
}




/*
run

c programming - 13.50

*/

 



answered May 3, 2021 by avibootz

Related questions

2 answers 230 views
2 answers 100 views
1 answer 128 views
1 answer 161 views
1 answer 155 views
...