Question: C program Why segmentation fault? Explain char * str; Printf(enter your input:) ; fgets(str, 20, stdin) ; Printf(%s, str) ; 2. Does this code fix
C program
Why segmentation fault? Explain
char * str; Printf("enter your input:") ; fgets(str, 20, stdin) ; Printf("%s", str) ;
2. Does this code fix it? Why or why not. If no, write your own code below
Void allocate_mem(char * str) { str = (char *) malloc (20* sizeof(char)) ; }
Int main(){
char * str; Printf("enter your input:") ; allocate_mem(str) ; fgets(str, 20, stdin) ; Printf("%s", str) ;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
