I am new to C and learning structs. I am trying to malloc a char pointer with size 30 but it is giving a segmentation fault(core dump). I searched it on the interne
malloc
You never allocated space for the struct itself, only a pointer to it.
Try something like:
str *p = malloc(sizeof(str));