This is my code:
#include<stdio.h>
struct p{
char* d;
};
typedef struct p* pt;
int main(){
pt opt;
opt=(pt)malloc(sizeof(struct p));
scanf("%s",(opt->d));
printf("%s",opt->d);
getch();
return 0;
}
Everytime I run it , it accepts and prints the string fine but an error occur.
On debugging it tells that there is a segmentation fault but doesn't points to where it is?
What is going wrong , It's seems to be fairly correct.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…