Thread: fancy strcpy

  1. #1
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    fancy strcpy

    is there a magic function that can combine two or more chars into a single char?

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    you mean like this?

    char result:
    char first = 'A';
    char second = ' ';
    result = first + second;
    cout << result;

    No function I know of, but shouldn't be too hard to do it yourself. Just need to wrap around value if using ASCII char set and sum of ASCII values for first and second is > 255.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    Code:
    char one = "a", two = "b";
    int three;
    three = (int)a + (int)b;
    cout<<(char)three;

  4. #4
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    //ASCII code stuff to bright for you to see
    Last edited by ErionD; 04-30-2002 at 10:23 AM.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    erion : he wants to add the scii, my post would be correct ^_^

  6. #6
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Ehh? He said that he wanted to combine two chars into one.
    Last edited by ErionD; 04-30-2002 at 10:24 AM.

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    combine two or more chars into a single char?
    combine two or more chars into a single char?
    combine two or more chars into a single char?combine two or more chars into a single char?combine two or more chars into a single char?
    combine two or more chars into a single char?combine two or more chars into a single char?combine two or more chars into a single char?
    combine two or more chars into a single char?vcombine two or more chars into a single char?
    vcombine two or more chars into a single char?
    vcombine two or more chars into a single char?combine two or more chars into a single char?combine two or more chars into a single char?combine two or more chars into a single char?combine two or more chars into a single char?combine two or more chars into a single char?combine two or more chars into a single char?combine two or more chars into a single char?combine two or more chars into a single char?



    starting to get the picture?
    he said CHAR not STRING.
    as in A + B.

  8. #8
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    I didnt say anything

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Here's one way:
    Code:
    char message[80];
    
    strcpy(message,"Hello");
    strcat(message," world");
    cout << message << endl;
    Or:
    Code:
    char message[80];
    char word[10];
    
    strcpy(message,"Hello");
    strcpy(word," world");
    strcat(message,word);
    cout << message << endl;
    Or with string types I think you can:
    Code:
    string message = "Hello" + " world";
    Last edited by swoopy; 04-30-2002 at 01:07 PM.

  10. #10
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    swoopy : read what i told erion, read his post. he didnt ask to combine STRINGS he asked to combine CHARACTERS. as in ascii...

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I kind of interpreted what he said, to what he really meant. I could be wrong.

  12. #12
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    if you combine characters you make a string don't ya?

    so make a char array of say 100 elements.. copy each char into the first two segments of your array then add the \0 to position three.. you now have a string, but u did add your two chars together!

    or just scan em in as strings and strcat!
    SS3X

  13. #13
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    TWO CHARACTERS INTO ONE. INTO ONE CHARACTER U STUPID MOFO.

    HOW ARE YOU PEOPLE SO STUPID? PUTTING 2 TOGeTHER MEANS TO CHARACTERS. ONE CHARACTER IS NOT ADDING STRINGS *craps pants*

  14. #14
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    I don't think heat511 knows what he wants. He probably wants to take two characters and turn them into a string, but nobody really knows b/c he doesn't understand the terminology.

    So everybody just chill out

  15. #15
    Registered User
    Join Date
    Apr 2002
    Posts
    200
    is there a magic function that can combine two or more chars into a single char?
    You are an idiot, denethor. Note the use of 'combine.' When you combine two items, you do not just add them together. As biosx said, heat's grasp of the terminology involved is not sufficient to be able to express himself clearly. BTW, is there something in the sentence "Please don't clutter the post up with CAPS." (from the FAQ) that you are incapable of understanding?

    *craps pants*
    young children tend to do that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Full Program to analyze.
    By sergioms in forum C Programming
    Replies: 2
    Last Post: 12-30-2008, 09:42 AM
  2. Strcpy
    By Godders_2k in forum C Programming
    Replies: 17
    Last Post: 12-12-2007, 12:34 PM
  3. Where is strcpy() defined? (Can't find in string.h ect)
    By Zero_Point in forum C++ Programming
    Replies: 6
    Last Post: 04-03-2006, 05:14 PM
  4. Question about strcpy
    By Kevinmun in forum C Programming
    Replies: 4
    Last Post: 11-02-2005, 11:00 PM
  5. strcpy
    By Luigi in forum C++ Programming
    Replies: 17
    Last Post: 02-16-2003, 04:11 PM