I am a beginner in C and I encountered problems when dealing with scanf
, hoping for an explanation behind this
this is my code
#include <stdio.h>
#include <math.h>
#include <string.h>
int fav_charac() {
char *string = "";
printf("whats your fav letter?: ");
scanf("%s", string); // the problem
printf("your fav letter is %s\n", string);
}
int main() {
fav_charac();
return 0;
}
and this is the program running
whats your fav letter?: a
C:\Users\DELL\source\repos\hello C\x64\Debug\hello C.exe (process 15052) exited with code -1073741819.
Press any key to close this window . . .
as you can see it exited right after an input is made, why?