need help on strings and integer merging

This is a discussion on need help on strings and integer merging within the C Programming forums, part of the General Programming Boards category; i am a beginner i have tried hours to figure out how to merge 2 strings and a integer into ...

  1. #1
    Unregistered
    Guest

    need help on strings and integer merging

    i am a beginner
    i have tried hours to figure out how to merge 2 strings and a integer into one string.
    if anyone can help me on that, i appreciate that.
    plz give me some codes too.
    thx

  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    See the help on sprintf()
    Code:
    #include <stdio.h>
    
    main()
    {
            char str[255], *s1 = "The", *s2 = " Number is: ";
            int num = 666;
    
            sprintf(str, "%s%s%d", s1, s2, num);
            puts(str);
    }

  3. #3
    Unregistered
    Guest
    sorry i did not mention something
    after merging 2 strings and 1 number to 1 string, then assig it to another variable

    for example,

    a = "the", b ="number is" c = 999;
    d = a + b + c
    so d is a string

    thx

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    That's what sprintf() do. Instead of writing to the screen (like printf()) it writes to the string (str as in Shaik's example).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    If you'll be displaying it without any further processing after this operation, printf can handle all that if you code in all the formating

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  3. Converting Strings To Integer In Linked List
    By rocky8015 in forum C Programming
    Replies: 3
    Last Post: 06-05-2005, 10:35 PM
  4. Need some help with integer strings
    By Guti14 in forum C++ Programming
    Replies: 4
    Last Post: 08-28-2003, 01:13 PM
  5. Strings to integer values
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 02-05-2002, 11:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21