char *p;
fgets(p,10,stdin);
Why is this crashing my program? Seems like I can't use char pointers in Fgets but I can use arrays so it makes no sense.
char *p;
fgets(p,10,stdin);
Why is this crashing my program? Seems like I can't use char pointers in Fgets but I can use arrays so it makes no sense.
Seems like I can't use char pointers in Fgets but I can use arrays
No, you can use both, as long as you allocate memory to the pointer before passing that to fgets().
In this case, using pointers,
char *p;
p is unitialized and points to some arbitrary memory location which is invalid. You need to allocate proper memory to p before you can read/write something to/from the memory location pointer by p.
fgets() wont allocate memory to the pointer. You need to allocate memory prior to passing the pointer.