joining trings without strcat()

This is a discussion on joining trings without strcat() within the C Programming forums, part of the General Programming Boards category; I need to make this program add the characters in source to the end of the string destination. the function ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    51

    joining trings without strcat()

    I need to make this program add the characters in source to the end of the string destination. the function assumes that there is enough room in destination to store the additional characters. I dont want to use srtcat().

    Can anyone help me with this please.
    Here is my program so far:


    #include <stdio.h>


    void join (char* destination, char* source) {

    /* My code goes here. */
    }


    int main () {

    char quick_fox [100] = "The quick brown fox";
    char jumps_over [100] = " jumps over the lazy dog.";

    printf("Joining \"%s\" to \"%s\"\n", quick_fox, jumps_over);
    join(quick_fox, jumps_over);
    printf("gives \"%s\"\n", quick_fox);
    }

  2. #2
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    did strcat() victimize you when you were a child?
    hello, internet!

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Tada, without strcat:
    Code:
    void join (char* destination, char* source) 
    {
        strcpy(destination+strlen(destination), source);
    }

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Here is my program so far:
    You have everything but the function you need. Is this because everything but the function you need was given to you to begin with?

    Here is a freebie:
    Code:
    void join ( char *dst, const char *src )
    {
      char *end;
      /* No body */
      for ( end = dst; *end != '\0'; end++ );
      /* No body */
      while ( ( *end++ = *src++ ) != '\0' );
    }
    Beware turning in other people's code for homework though, teachers can usually tell if it is not yours.

    -Prelude
    My best code is written with the delete key.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An interesting question about strcat
    By meili100 in forum C++ Programming
    Replies: 3
    Last Post: 07-07-2009, 12:59 PM
  2. argv change
    By dracayr in forum C Programming
    Replies: 9
    Last Post: 04-10-2009, 02:49 AM
  3. strcat and a char
    By jjacobweston in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2005, 04:10 PM
  4. strcat makes program crash
    By imoy in forum C++ Programming
    Replies: 4
    Last Post: 05-09-2002, 02:41 PM
  5. Removing 'strcat' ed string.
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 11-13-2001, 11:09 PM

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