The commenters found most of it, so to put it all together
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
// ALL CHECKS OMMITTED!
int main()
{
int16_t frame[5] = { 10, 2, 3, 7, 5 };
// hexadecimal string = 2 characters plus NUL
// sizeof(char) == 1, if compiler is standard compliant
char *str = malloc(3 * (sizeof(frame)/sizeof(frame[0]) +1));
char *strp = str;
size_t j;
for (j = 0; j < sizeof(frame)/sizeof(frame[0]); j++) {
// again: hexadecimal string = 2 characters plus NUL
snprintf(strp, 3, "%02x", frame[j]); //hexadecimal
strp += 2;
}
// we need a pointer to the start of the string to free it later
strp = str;
// let's see if we gott all of them
printf("str = %s\n",str);
// from hexa string to 16 bit integer array
int16_t n_oframe[5];
size_t i_m;
// and again: hexadecimal string = 2 characters plus NUL
// a simple char d[3]; would have been more than suffcient
// for the task, but if stack is precious...
char *d = (char *) malloc(3);
for (i_m = 0; i_m < 5; i_m++) {
// it's always the same, just do it once at the beginning
//char *d = (char *) malloc(3);
strncpy(d, str, 2);
// atol() is for base 10 input only, use strtol() instead
n_oframe[i_m] = (int16_t)strtol(d,NULL,16);
str = str + 2;
//free(d);
}
for (j = 0; j < 5; j++) {
printf("%d ", n_oframe[j]);
}
putchar('\n');
free(d);
free(strp);
exit(EXIT_SUCCESS);
}
I changed gint16 to int16_t because I do not know what that is supposed to be. You can most likely replace it with gint16 without problems.
sizeof(char) * (sizeof(frame)+1)supposed to give? Especially given the type offrame..sizeof frame / sizeof frame[0].free(str);would crash as you have incremented str.