Question: So i'm trying to create a simple String struct which will contain the text of the string and the size of it, at least for now. However I'm having issues allocating my struct. Right now i'm simply trying to get a size of 1 character to work, but its simply crashing at this point and i don't know what i'm doing wrong with the allocation, please help.

```
#include <stdio.h>
#include <stdlib.h>

typedef struct{
    char* text;
    int size;
}String;

String* getString();

int main(int argc, char** argv){

    String* str1 = getString();
    printf("%s",str1->text);    
    free(str1);
    return 0;
 }

String* getString(){
    String* str = (String*)malloc(sizeof(String));
    scanf("%s",str->text);
    str->size++;
    return str;
}

```

Answer: 
You need to allocate memory for the structure but also for `text` string.

```
scanf("%s",str->text);

```

`str->text` is an uninitialized pointer.
```
int main(int argc, char** argv){
    String* str1 = getString();
    printf("%s",str1->text);
    free(str1->text);
    free(str1);
    return 0;
 }

String* getString(){
    String* str = (String*)malloc(sizeof(String));//for struct
    str->size = 16;//initialize
    str->text = (char*)malloc(sizeof(char)*str->size);//for input text
    int ch, len;
    while(EOF!=(ch=fgetc(stdin)) && ch != '\n'){
        str->text[len++]=ch;
        if(str->size==len){
            str->text = realloc(str->text, sizeof(char)*(len+=16));
        }
    }
    str->text[len++]='\0';
    str->text = realloc(str->text, sizeof(char)*(str->size=len));
    return str;
}

```