append 2 strings into one variable

This is a discussion on append 2 strings into one variable within the C Programming forums, part of the General Programming Boards category; What I am wanting to do is: char LINK[] = "http://127.0.0.1/exec.php?cmd= I'll use scanf to get the command (COMMAND) scanf("%s", ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    29

    append 2 strings into one variable

    What I am wanting to do is:
    char LINK[] = "http://127.0.0.1/exec.php?cmd=
    I'll use scanf to get the command (COMMAND)
    scanf("%s", &COMMAND);
    Then I would like to append LINK and COMMAND together into one variable to send over socket.
    I heard this can be done with strcat.
    I am very new to C, if you can provide an example that would be great.
    -Thanks in advance

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    Read this

    -Micko
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    29
    Code:
    // Playing with strcpy
    
    #include <stdio.h>
    #include <stdlib.h>
    
    char first, second;
    
    int main()
    {
    printf("Input first>");
    scanf ("%s", &first);
    printf("Input second>");
    scanf ("%s", &second);
    
    //overlaps second over first
    char *strcpy(char *first, const char *second);
    
    printf("%s\n", &first);
    printf("%s\n", &second);
    return (0);
    }
    Yes, oddly enough the man pages were the first thing I checked. Here is some code I'm playing with that is not working like it should at all. Please any help.

  4. #4
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    Quote Originally Posted by stormy
    Code:
    // Playing with strcpy
    
    #include <stdio.h>
    #include <stdlib.h>
    
    char first, second;
    
    int main()
    {
    printf("Input first>");
    scanf ("%s", &first);
    printf("Input second>");
    scanf ("%s", &second);
    
    //overlaps second over first
    char *strcpy(char *first, const char *second);
    
    printf("%s\n", &first);
    printf("%s\n", &second);
    return (0);
    }
    Yes, oddly enough the man pages were the first thing I checked. Here is some code I'm playing with that is not working like it should at all. Please any help.
    first and second are type char and that is probably not what you want.
    you sholud use char first[BUFSIZ] or something similar and fgets function to enter line of text.

    Check FAQ!

    Also you don't need addrress operator & in printf and your use of strcpy isn't correct


    - Micko
    Last edited by Micko; 08-15-2005 at 02:44 AM.
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Join 2 strings inside 'fopen'?
    By tomas.ra in forum C Programming
    Replies: 5
    Last Post: 09-24-2005, 05:08 PM
  2. Replies: 2
    Last Post: 04-12-2004, 02:37 AM
  3. float/double variable storage and precision
    By cjschw in forum C++ Programming
    Replies: 4
    Last Post: 07-28-2003, 07:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. c-style string vs. c++-style strings
    By Mbrio in forum C++ Programming
    Replies: 3
    Last Post: 02-10-2002, 12:26 PM

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