I have C code that includes header and c files. In header which is string.h I defined the functions and implement in them in string.c and in the main.c I am testing my program. I want to allocate memory for char and check if it is okay then I want to free. But I got error from visual studio code that "The breakpoint directive (__debugbreak() statement or similar call) was executed in StringC.exe." or "Acces violation to read error"
Here is my string.h :
#include<stdio.h>
#include<stdlib.h>
typedef enum
{
string_return_success,
string_return_allocation_error,
string_return_source_overflow,
string_return_destination_overflow,
string_return_not_found
} StringReturnType;
typedef unsigned int StringSizeType;
StringReturnType stringCreate(char *str, StringSizeType size);
void stringDestroy(char *str);
Here is my string.c :
StringReturnType stringCreate(char *str ,StringSizeType size)
{
char temp = *str;
str = (char*)malloc(sizeof(char) * (size));
*str = temp;
if (*str == NULL) {
printf("burdayim");
return string_return_allocation_error;
}
printf("%c", *str);
}
void stringDestroy(char *str)
{
free(str);
}
And here is the main:
int main()
{
char str = 'h';
char* ptr = &str;
stringCreate(ptr, sizeof(str));
stringDestroy(ptr);
return 0;
}