0 votes
in C Plus Plus by
How can a number be converted to a string in C, explain with example.

1 Answer

0 votes
by

The function takes a pointer to an array of char elements that need to be converted, and a format string needs to be written in a buffer as a string

int sprintf(char *str, const char *format, ...)

 

#include<stdio.h>
#include <math.h>
int main()
{
char str[80];
sprintf(str, "The value of PI = %f", M_PI);
puts(str);
return 0;
}

The output after running the above code:

Output: Value of Pi = 3.141593

Related questions

0 votes
asked Jan 6 in C Plus Plus by GeorgeBell
0 votes
asked Jan 12 in C Plus Plus by GeorgeBell
...