Когда я пытаюсь получить строку из функции типа void*
, я получаю только первый символ.
Я пытался скопировать строку вручную без использования strcpy()
, это вызывает у меня ту же проблему
struct arr {
int first
int last.
void **val;
};
//I have a function which is called
void *inspect_arr(const arr *ar, int position)
{
....
return ar->val[offset];
}
//I want to inspect the array so that I can compare the strings
int main()
{
char *str = calloc(10,sizeof(char));
char *k = *(char*)inspect_arr(...) //I have a string in the array
// strcpy(str,k); Doesn't work
strcmp(str,k); Invalid read from valgrind
//If array has an integer type then I would write my code like this:
//int a = *(int*)inspect_arr(...) but I can not do the same thing for char
}
При запуске программы возникает ошибка сегментации.