Question & Answer: Describe the mistake in this code snippet…..

Describe the mistake in this code snippet

char* x;

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: Describe the mistake in this code snippet…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

strncpy(x, “Hello”, strlen(“Hello”)+1);
—————————————————————-

Describe the mistake in this code snippet

char* x = “Hello!”;

strncpy(x, “Hello.”, strlen(“Hello.”)+1);
—————————————————————–

Describe the mistake in this code snippet

char* x = “This is a test”;

char* y = “This is another test”;

char* token = strtok(x, “ “); // Expecting ”This”

char* token2 = strtok(y, ” ”); // Expecting “This”

char* token3 = strtok(x, ” ”); // Expecting “is”

——————————————————————

Expert Answer

 

1) By definition of strncpy function the first parameter is a pointer to destination array where the content will be stored and here x is not an array it’s just a pointer.

2) Again as explained above it needs to be an array which can store the result.

Still stressed from student homework?
Get quality assistance from academic writers!