Thread: adding a char at the end of a number

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,127
    Compare the versatility of sprintf() to multiple functions in your code:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
      int ival = 1234;
      double dval = 1.2345;
      char ary[64] = "";
    
    // Build a string with an int, int in Hex, address of the int, and the the double
    
      sprintf(ary, "int=%d, hex=%x, addr=%p, double=%lf\n", ival, ival, (void *) &ival, dval);
    
      printf("ary = %s\n", ary);
    
      return 0;
    }
    Code:
    Output:
    ary = int=1234, hex=4d2, addr=0x7ffd3ba48224, double=1.234500
    Last edited by rstanley; 10-15-2023 at 11:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adding a number at the end of a char
    By WaterSerpentM in forum C Programming
    Replies: 6
    Last Post: 10-15-2023, 07:54 AM
  2. Adding one to every digit of number
    By culater in forum C Programming
    Replies: 3
    Last Post: 06-04-2015, 06:36 AM
  3. Replies: 6
    Last Post: 07-15-2008, 02:27 PM
  4. What's problem of adding two binary number?
    By Mathsniper in forum C Programming
    Replies: 1
    Last Post: 01-12-2007, 06:12 AM
  5. Adding .txt to a char
    By ErionD in forum C++ Programming
    Replies: 11
    Last Post: 02-22-2002, 04:01 PM

Tags for this Thread