2016年3月17日 星期四

[C] How to memory copy to pointer


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void main()
{
    char tmp[256] = {'\0'};

    char *go = (char *)malloc(sizeof(char)); // Must assign a space to the pointer of go
    sprintf(tmp,"gogo");

    memcpy(go,tmp,sizeof(tmp));  // memory copy
    printf("%s\n",go);
}


Reference:

0 意見:

張貼留言