In you first code, a is an uninitialized pointer to char.
You are trying to write to non-allocated memory or reserved memory.
You need to allocate memory for the input string with malloc().
int main(void) {
char* s;
/* ... */
s = malloc(100 * sizeof(*s));
if (s == NULL) {
return 1;
/* ... */
}