How to use Macros and sprintf In C Language

C




// C Program for Long to 
// String Conversion
#include <stdio.h>
#include <string.h>
  
#define Max_Digits 10
int main()
{
    long N = 1243;
    char str[Max_Digits + sizeof(char)];
    sprintf(str, "%ld", N);
    printf("string is: %s \n", str);
}


Output

string is: 1243 

C Program For Long to String Conversion

To convert the long to string in C language we will use the following 2 approaches:

  1. Using Macros with sprintf
  2. Using sprintf

Input: 

long = 1234 

Output: 

string 1234

Similar Reads

1. Using Macros and sprintf

C // C Program for Long to  // String Conversion #include #include    #define Max_Digits 10 int main() {     long N = 1243;     char str[Max_Digits + sizeof(char)];     sprintf(str, "%ld", N);     printf("string is: %s \n", str); }...

2. Using Sprintf

...

Contact Us