문제

Why does Edit work. and Edit 2 fail to work like edit 1? Also how to make Edit2 work like Edit?

Edit: Working code from comment:

#include <stdio.h>

int main()
{
    char recBuffer[8024];
    char* temp = (char*)malloc(65536);

    strcpy(recBuffer, "Hello\n");

    int bytesRead = 7;
    memcpy(temp , &recBuffer, bytesRead );

    printf("%s\n", temp);

    return 0;
}

EDIT 2 Why this fails?:

#include <stdio.h> 

void Append(char* b, char data, int len)
{
    memcpy(b , &data, len ); 
}

int main() 
{ 
    int bytesRead = 7; 
    char recBuffer[8024]; 
    char* temp = (char*)malloc(65536); 
    strcpy(recBuffer, "Hello\n"); 
    Append(temp, recBuffer, bytesRead);    
    printf("%s\n", temp); 
    return 0; 
}
도움이 되었습니까?

해결책

Because your function parameter is char not char*. You should make the data parameter char* and pass it in directly to memcpy instead of passing its address.

다른 팁

The second argument of Append is a char, not a char*!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top