Overall goal statement :
Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters.
I have two arrays of the same size. if I want to remove the first and last element in the first array and add them to next array.
suppose that I can't change the size of second array to (sizeof(firstarray) - 2)
in the initial declaration;
if first array(string) is -
char* array1[] = {"eloquent"};
and then the second array should be -
char* array2[] = {"loquen"};
I tried to do it and it does not work in some cases.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* remove_char(char* dst, const char* src)
{
free(dst);
dst = malloc(((int)sizeof(src) - 2));
for (int i = 1; i < ((int)sizeof(src) - 1); i++)
{
dst[i - 1] = src[i];
}
/* src is the input string */
/* your solution should write the result into dst and return it */
return dst;
}