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 8671379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:56:09+00:00 2026-06-12T18:56:09+00:00

I want to assign a char* to char* , if I use strcpy I

  • 0

I want to assign a char* to char* , if I use strcpy I get several run time memory problem so I fix it by simple assignment using = operator.
Can any one explain what should prepare before using strcpy to avoid memory issues.

EDIT:

int Function(const char* K,char* FileIN,char* FileOut,int DC)
{   
    char *fic_in,*n_fic,*fic_out,*fic_dec;

    unsigned char k[17];

        fic_in = (char*)malloc(60*sizeof(char));

        strcpy((char*)k,K);

        //strcpy(fic_in,FileIN);  //I remove this one
        fic_in=FileIN;            //and replace it by this
      ...
  • 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-06-12T18:56:10+00:00Added an answer on June 12, 2026 at 6:56 pm
    const char *a = "string literal";
    const char *b;
    

    a is a pointer that points to a string literal. b is a pointer that doesn’t point anywhere in particular (it is uninitialized).

    b = a;
    

    b now points to the same memory that a points to.

    char c[100];
    

    c is now an array of 100 chars. That area of memory is completely separate from everything else so far.

    strcpy(c, a);
    

    The contents of c (to be specific, the first 15 bytes) now hold the same values as the memory pointed to by a. So now there are two regions of memory that contain the same string data.

    So as you can see, assigning pointers has pretty much nothing in common with strcpy. If you want to assign a char* to a char*, then you shouldn’t be anywhere near strcpy.

    It’s essential that you read a book about C++, but the basic requirement for strcpy is that the destination pointer must point to a region of memory with enough space for the string that the source pointer points to. Probably your “run time memory problems” were because you didn’t ensure that, which is why you need to read a book.

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

Sidebar

Related Questions

I want to assign the array item into variable directly using groovy like this:
I want to assign the value of aphostrophe to a char: char a =
I have: char *str = abc def abcdef ghi xyz; I want to assign
Question One I have var example : array[0..15] of char; I want to assign
I want to assign string to char array here is code - char *resultArray[100];
I have an unsigned char* type and want to assign it an integer value.
I want get the value from Exec(@sql) and assign to @Rowcount(int) Here is my
I want to assign a string like: 22 33 to a variable like char*av[129]
I want to assign a value from a select box to an input field
I want to assign the value in QString to a const std::string QString qfile(some

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.