#include<stdio.h>
#include<string.h>
struct logic
{
char ch[10];
char x;
int y;
char z;
//int i;
};
int main()
{
struct logic *p;
strcpy(p->ch,”hello”);
p->x=’b’;
p->y=42;
p->z=’c’;
printf(“%s\n%c\n%d\n%c\n”,p->ch,p->x,p->y,p->z);
}
#include<stdio.h>
#include<string.h>
struct logic
{
char ch[10];
char x;
int y;
char z;
//int i;
};
int main()
{
struct logic *p;
strcpy(p->ch,”hello”);
p->x=’b’;
p->y=42;
p->z=’c’;
printf(“%s\n%c\n%d\n%c\n”,p->ch,p->x,p->y,p->z);
}
when ever you use a structure pointer varible you need to allocate memory to the structure
p=malloc(sizeof(struct logic));
otherwise Segmentation fault
do one thing use p insted of (*p) then calculate sizeof(structure )
you will get the size of the whole structure
but in case of pointer no memory is allocated ,malloc is mandatory here