Thread: TCHAR * to unsinged char []

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    68

    TCHAR * to unsinged char []

    Hi Everyone,

    I have a question? i have a TCHAR array(Wide charater array), and its size is 78. That has hex data which is as following "D2D10131A102CAF100125202CF8102F8F1006CF1001661014 8F000BCD20087F20099E103310102". I want to copy it over to unsigned char array, and the size of it is 39. How do i copy this data. I am lost big time. basically i need to read two characters at a time from TCHAR array, and assign it to unsigned char array. And i want to keep the data as it is. Please help me....

    Example:
    read D2 from tchar array and assign to frist index of unsinged char array

    Thank You
    Pratik Parikh

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Allocate a dynamic array of unsigned char that's the same size (in bytes) as the TCHAR array, then memcpy the TCHAR array into the unsigned char array.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    68

    TCHAR * to unsinged char []

    hi Their,

    I did a mistake above, i want to scan D2(hex) and convert it into a unsigned char and then store it in to unsigned array. Sorry for the misunderstanding.

    Thank You,

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    68

    This problem is sloved

    Hi Everyone,

    This problem is solved, thank you for your help.

    Thank You,
    _P

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >i want to scan D2(hex) and convert it into a unsigned char and then store it in to unsigned array.
    Oh, well that's different then. I'm glad you solved your problem.
    My best code is written with the delete key.

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    A better way to conver wide char arrays to normal C type char arrays is to use a runtime function like wctombs - http://msdn.microsoft.com/library/de...t_wcstombs.asp

    A far better way is to avoid a conversion unless absolutely neeeded. You are using a TACHR array so therefore in reallity the array could be multibyte or wide char, but the benefit of TCHAR is that you dont need to know - compile as UNICODE and you use UNICODE functions and data types, compile as normal and you use multibyte variables and functions.

    You should only need the distinction if you are forced to use one specific typr for a function or you are playing with memort directly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  4. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  5. Extra printed stmts...why?
    By mangoz in forum C Programming
    Replies: 4
    Last Post: 12-19-2001, 07:56 AM