I am trying to store the input string value in a char pointer first, then, caste it to an integer pointer and then save it in an integer variable, but I am getting wrong output.Code:#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> void St2Int() { char inp[10]; printf("Input String number\n"); scanf("%s", inp); int *p; p = (int *)malloc(strlen(inp)); p = (int *)(inp); int res = *p; printf("%d\n", res); }
My method is stupid but I am a beginner and curious why this code is not working.