Code:
int main()
{
char *name=NULL;
int n;
printf(\"\\nenter the string\\n\");
scanf(\"%s\",name);
n=strlen(name);
printf(\"%d\",n);
return 0;
}
>
Try this,
int main()
{
char *name = malloc(sizeof( char ) * LENGTH); // define LENGTH as you desired
int n;
printf("\nenter the string\n");
scanf("%s",name);
n=strlen(name);
printf("%d",n);
free(name);
}
Problem is you did not allocate memory for pointer. So allocate memory tp pointer with malloc(BUFSIZE)
. Also at the end you have to free your allocated memory with free(name)
.