Thread: Problem with strings

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    2

    Problem with strings

    hey,

    i need help with transforming intergers into strings. I will have 2 intergers that i will have to make into a string and then display it as a file name. how can i do this without using sprintf.
    so the file name should look like this "list24to30.txt" where 24 and 30 are the intergers that were entered. can anyone help me please. Thanks.

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Well, since your teacher doesn't want you to use sprintf(), you should write your own function similar to itoa() that accepts an integer and returns a string.

    First, you need to be able to break an integer into its respective digits. Then, you need to change each digit to its character equivalent.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    2
    i can break the intergers into their character equavalents but i dont know how to put them together into a single string, since my intergers can range from 1 to 1000, i dont know how many character variables will be needed.

    if my interger is 131, then i had,

    a = 1
    s = 3
    d = 1

    but how can i put them together into a single string.

    then i had char str[] = a,s',d
    which would give me a string of 131 but next time my varaible would be 13, but then the char 'a' would not be used. how can i get around that?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compare strings problem
    By chelito19 in forum C Programming
    Replies: 2
    Last Post: 04-16-2009, 08:01 PM
  2. Problem with comparing strings!
    By adrian2009 in forum C Programming
    Replies: 2
    Last Post: 02-28-2009, 10:44 PM
  3. Problem with Strings and Conversions
    By patso in forum C Programming
    Replies: 8
    Last Post: 04-09-2008, 12:01 PM
  4. problem with strings
    By agentsmith in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 12:07 PM
  5. copy strings problem
    By dgcampos in forum C++ Programming
    Replies: 4
    Last Post: 04-23-2004, 08:05 PM