I'm curious if this can work somehow? My goal would be having a dynamic string structure and have functions that operate it more extensively than the standard library. However, I don't want to delete a string after going out of scope every time. Is there any way for strcpy() to copy a value into a String.text? I'm getting an access violation exception right now when it enters strcpy().
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct tagString
{
char *text;
} String;
void String_SetText(String *ob, const char *value)
{
strcpy(ob->text, value);
}
char *String_GetText(String *ob)
{
return ob->text;
}
int main(void)
{
String str;
String_SetText(&str, "Hello World!");
printf("%s\n", String_GetText(&str));
system("pause");
return 0;
}