Alex Larose

Generation

generate functionWed, 29 Mar 2023

Write a C-callable assembler version of the library strncpy function called mystrncpy (to avoid conflicts with the library version) that copies the contents of one string to a user provided array and returns a pointer to the provided array. The function prototype is: char *mystrncpy(char *s, char *ct, int n); Write your code in a source file named strncpy.s. The provided C driver (strncpyc.c) in mp2/part2+3/ takes user entered input for the source string and checks both the pointer returned and the effect of the copy. Choose test cases that exercise different possibilities in the logic of your code, e.g. a null string. What would happen if you choose a string longer than the destination array in the C driver?

public class Mystrncpy { public static void main(String[] args) { char[] s = {'a', 'b', 'c', 'd'}; char[] ct = {'e', 'f', 'g', 'h'}; int n = 3; char[] result = strncpy(s, ct, n); System.out.println("result = " + Arrays.toString(result)); } public native char[] strncpy(char[] s, char[] ct, int n); static { System.loadLibrary("strncpy"); } }

Questions about programming?Chat with your personal AI assistant