Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6344255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:35:56+00:00 2026-05-24T20:35:56+00:00

I am using two buffers which are of unsigned char and when I used

  • 0

I am using two buffers which are of unsigned char and when I used the function strcpy, there is a compilation error which says “invalid conversion of unsigned char * to char *”. Can anyone please tell me what difference does an unsigned buffer vs. signed buffer makes to the output? This is the program which I had tried.

        main()
        {
                unsigned char buff[20] = "Michael";
                unsigned char dst[20] = "Jackson";
                strcpy(buff,dst);
                printf("The string is %s\n",buff);

        }

Now when i typecast the parametrs passed in strcpy to (char *),This programe works fine as shown below

        main()
        {
                unsigned char buff[20] = "Michael";
                unsigned char dst[20] = "Jackson";
                strcpy((char *)buff,(char *)dst);
                printf("The string is %s\n",buff);

        }

2nd Question: Does typecasting to char* in the string function create any issues?

Please do let me know if you need any more inputs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:35:57+00:00Added an answer on May 24, 2026 at 8:35 pm

    You can just change:

    unsigned char buff[20] = "Michael";
    unsigned char dst[20] = "Jackson";
    

    to

    char buff[20] = "Michael";
    char dst[20] = "Jackson";
    

    To think of it logically, A string cannot be signed or unsigned, it is not a numeric value to be treated that way, it is just an char array and you should declare and use it so.

    Why do you get the error?
    strcpy has the prototype:

    char *strcpy(char *restrict s1, const char *restrict s2);
    

    And what you are passing to it is, unsigned char*, when a function is called parameter type checking takes place and the compiler finds that you are not calling the function with proper type parameters and hence it complains about it, When you apply a cast the function arguments match and hence compilation passes.

    Does typecasting to char in the string function create any issues?*
    No, in this case it doesn’t.
    Though it makes more sense to change your usage of unsigned char for the reasons mentioned above in the answer.

    Suggestion:
    Strcpy is not safe, so you are much better off using strncpy, it allows you to explicitly specify how many characters to copy, rather than rely on null terminator of the source string, Also this helps avoiding buffer overflow since you explicitly specify a length.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's say currently there are two buffers in my vim session, and I want
I'm using two different libraries in my project, and both of them supply a
I'm using two commercial libraries that are produced by the same vendor, called VendorLibA
I'm currently using two libraries (prototype and jQuery), thus I've implemented the jQuery noConflict
I currently am using two stylesheets to get my intended output. The first stylesheet
I'm using two different version of php on two different OS's. One is 5.2.9
In Django I am using two applications: python manage.py startapp books python manage.py startapp
I was using two TButton components on a form that functioned as Plus and
I am currently using two catch blocks after a try block. The first catches
I'm using two bindings TCP and HTTP. I want to give mex data on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.