Generation

generate functionMon, 27 Mar 2023

function that receives a char pointer, removes the first and last characters and returned the modified string.

#include <stdio.h> #include <stdlib.h> #include <string.h> char *remove_first_last(char *str) { int len = strlen(str); char *result = (char *) malloc(sizeof(char) * (len - 1)); strncpy(result, str + 1, len - 2); return result; } int main() { char *s = "First Last"; char *res = remove_first_last(s); printf("%s\n", res); return 0; }

Questions about programming?Chat with your personal AI assistant