Hello,

My program looks something like this:

char *name= (char *)malloc(200);

unsigned char type=1;

unsigned char GetType(){
    return type;
}

char* GetName(){ 
    return name;
};


void function(unsigned char* message, int* intPtr){

    message[0]= GetType(); // works correctly
    
    // CODE HERE    

}



void main(){

unsigned char *message= (unsigned char *) malloc(256);

int *ptrInt = (int *)malloc(sizeof(int));

function(message, ptrInt);

printf("message[0]= %d",message[0]); // works correctly

}

I have a pointer to an array of 256 unsigned chars. I am parsing that pointer as a parameter to function(message, intPtr).

Inside function(), I want to load the first byte from my array ( message[0]) with an integer from 0-255 (works).

Next, I want the bytes from 1... strlen(name) to store the name. How can I do that?

For instance, I've tried:

void function(unsigned char* message, int* intPtr){

		char *xxx=GetName(); //or even

                char *xxx; xxx=GetName();

		printf("\nGetName: \n");
		
		while (*xxx)
			printf("%c",*xxx++);

		memcpy(message+1, GetName(), strlen(GetName());

}

Ideas, please?

Edited 5 Years Ago by Buffalo101: n/a

why are you calling GetName() so many times??? And for what purpose is the second parameter to that function?

char* xxx = GetName();
if( xxx != NULL)
{
   printf("%s\n", xxx);
   memcpy(message+1,xxx,strlen(xxx));
}

Edited 5 Years Ago by Ancient Dragon: n/a

This article has been dead for over six months. Start a new discussion instead.