Since no-one's actually bothered to answer your question:
why doesn't work the following code? |
... I'll do that.
It doesn't work, because you haven't initialised
a. The value of
a is undefined, which means you have no idea what memory it's pointing to. It could be NULL, or it could be a random block of memory that's being used for something else.
On line 7, when you try to write data to the memory
a is pointing to, you have undefined behaviour - most likely, your program crashes.
What you need is to have
a point to some memory you've allocated to hold the string. Furry Guy has shown you how to do this.
By the way, "doesn't work" is a pretty useless problem description. You should give us a clear, precise and complete description of the behaviour you're seeing, and how it differs from the behaviour you expect.