char = char?

This is a discussion on char = char? within the C++ Programming forums, part of the General Programming Boards category; hi all i have a quick question, how do i convert a char into another char such as: char name, ...

  1. #1
    dizz
    Guest

    char = char?

    hi all i have a quick question, how do i convert a char into another char such as:

    char name, name2;

    name="bobo";

    name2=name;

    Any help would be great.. im thinking it has something to do with the string.h include.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    im thinking it has something to do with the string.h include.
    No it has to do with the C book that's gathering dust on your shelf.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  3. #3
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Dude, you're confused. Those variables declared are only single characters. Not full words. So the following would not work:
    Code:
    char name, name2;
    
    name="bobo";
    
    name2=name;
    To fix this do this:
    Code:
    char name[100]; // an array of 100 little characters to make up a whole word or sentence
    char name2[100]; // same as above
    
    strcpy(name, "bobo"); // assign the string "bobo" to name
    strcpy(name2, name); // now assign whatever is in name to name2

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Its also okay to do any of the following

    Code:
    //example 1
    char name[]="bobo", *name2=name;
    
    //example 2
    char *name="bobo", *name2=name;
    
    //example 3
    char name[10] = "bobo", *name2=name;
    
    //example 4
    char name[10] = "bobo", name2[10];
    
    strcpy(name2, name);
    
    //there are other variations but you get the idea

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  3. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM
  4. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 10:55 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 12:18 AM

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