Copying integer to integer with allocated memory

13,479

Just dereference anotherInteger.

*anotherInteger = anInteger;

strncopy is for strings.

Share:
13,479
Fjodor
Author by

Fjodor

Updated on June 05, 2022

Comments

  • Fjodor
    Fjodor almost 2 years

    I have a problem with the code below.

    ...
    int anInteger;
    ...
    //anInteger gets a value
    ...
    
    int *anotherInteger;
    label = (int *)malloc(sizeof(int));
    strncpy(anotherInteger, anInteger, 40);
    

    Essentially what I want to do is to copy the value from an integer to my other integer which I have allocated memory for. Can this work with strncpy between integers or do I need another function?