Hi All,
I have a problem with this code. I am using a gcc compiler and when i compile and execute this code i am getting a seg fault. I am just assigning two variables, name_1 as pointer and name_2 as string. When i am trying to provide string input for the two values i am getting a seg fault. This seg fault is always associated with the pointer variable that i am using.
Code:
#include <stdio.h>
int main()
{
char *name_1 ;
char name_2[10] ;
/* Getting 2 strings as an input from the user
and is stored in the pointer variable name_1 and name_2*/
scanf("%s",name_1) ;
scanf("%s",name_2) ;
/* Printing the values of the varibales
name_1 and name_2 in string format */
printf("\n%s",name_1) ;
printf("\n%s",name_2) ;
printf("\n\n") ;
return 0 ;
}