Thread: int and char concatenation question

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    49

    Question int and char concatenation question

    Code:
    char *t_ptr;
    int *ts;
    
    case 555:
    	strcpy(t_ptr, "\\555\\");
    	t_ptr += 5;
    	strcpy(t_ptr, (char *) ts);
    	break;
    I just need to concatenate t_ptr and ts, but my line of code: strcpy(t_ptr, (char *) ts); does not work. How would I correctly concatenate those two variables? If it's an easy answer, then great! If not, then I'll try to pull out more of my code that's relevant in order for somebody to help me. Thanks!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    Code:
    sprintf( t_ptr, "\\555\\%d", *ts );
    Does the whole lot.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You haven't allocated anything for your pointers. First off, fix that. Then use something like sprintf to copy whatever your int pointer points to a buffer. Then strcat the buffer to your first one.

    [edit]
    Curses, foiled again!
    [/edit]

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    49
    Thanks Salem...I was trying to be more complicated then what was really called for

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  3. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  4. Display Lists (OpenGL)
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 06-05-2005, 12:11 PM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM