Ask about how to change from unsigned char to char

This is a discussion on Ask about how to change from unsigned char to char within the C++ Programming forums, part of the General Programming Boards category; I want to ask about how to change from unsigned char to char. This below is some part of my ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Ask about how to change from unsigned char to char

    I want to ask about how to change from unsigned char to char. This below is some part of my code which wrong. Do you know how to correct my code for changing unsigned char to char. Thank you very much.

    code
    .................................................. ...................................
    CArray<unsigned char, unsigned char> m_data;
    char* argv;
    int k = 0;
    for (i=0; i< m_data.GetSize(); i++)
    {
    argv[i] = m_data[i];
    }
    .................................................. ...................................

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    ok, the first way this code is wrong is that you never allocated memory for char *argv. it is an uninitialized pointer. so you will have a memory access error. Second, once you have allocated the memory, your assignment probably needs to cast. as in the following:

    argv[i] = (char*)m_data[i];

    Have fun.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input class project (again)
    By Elysia in forum C++ Programming
    Replies: 41
    Last Post: 02-13-2009, 09:52 AM
  2. A Full Program to analyze.
    By sergioms in forum C Programming
    Replies: 2
    Last Post: 12-30-2008, 08:42 AM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM

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