Renjith G
Renjith G

Reputation: 4908

character array handling in c (copy pointer to character array)

I have a pointer with type const char* FunctionName , How can I put that into a payload of type char payload[100] without any warning or errors? Also the payload[0] is filled with character value already, so the space starting from payload[1]

update:

I tried like this `strcpy((&payload[1]),FunctionName); is working now.

But Ihave one more question, how can accomodate the pointer(FunctionName) into the payload[1] ratherthan copying the entire string? through any assignment statement?

/R

Upvotes: 0

Views: 606

Answers (1)

Vicky
Vicky

Reputation: 13244

strncpy(&payload[1], FunctionName, 98);
payload[99] = '\0';

should be safe in the case that FunctionName has more than 98 characters before the NULL terminator.

Upvotes: 3

Related Questions