Thread: little prob with string?

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    4

    Question little prob with string?

    hi all,
    i want to convert string like "\x52\x49" to ascii

    when i use this code in Turbo C :
    Code:
    unsigned char test[] = "\x52\x49";
    printf("%s",test);
    i've gud result is : RI

    but when i use in Visual C++ , with m_Input and m_Output are variables from text box
    Code:
    unsigned char test [] = m_Input;
    m_Output = test;
    i've error cus it cant convert char to CString.
    so how can i fix this prob ?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Use plain char, not unsigned char.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Also, do you have to use strcpy() or something? If you're using C++ use std::strings.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    He's apparently using MFC's CString.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    4
    Quote Originally Posted by CornedBee
    Use plain char, not unsigned char.
    ya i used char test[] , instead unsigned but there still an error that cannot convert from CString to char

    Quote Originally Posted by twomers
    Also, do you have to use strcpy() or something? If you're using C++ use std::strings.
    ya i tried with strcpy() function but it result m_Input to m_Output , like i told , i want something like if m_Input is "\x52\x49" , m_Output will be "RI" , cus it worked in Turbo C , but not work in VC++
    thanx 4 all ur helps!

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    A CString can be converted to a const char* automatically. If you want a copy of the CString in a C style array, then you need to use strcpy.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Can you show the full code snippet that worked in Turbo C and the one that didn't in VC++?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM