Um...where are you learning to program in C? This way of allocating memory is really used anymore. That, and you don't have to include alloc.h, the function malloc is in stdlib.h.
> if ((str = (char *) malloc(10)) == NULL)
On this line, it is definitely not good practice to allocate memory in the if statement. It really should be:
Code:
str = (char *) malloc(10);
if (str == NULL)
...etc...
This is more readable, especially when you have to debug. Also, your allocation statement:
> str = (char *) malloc(10);
is right, but a little out-dated. What compiler are you using? You can allocate the memory like this:
> str = malloc(10);
you don't need to typecast when you allocate in the more recent compilers. You can do your way, I'm just showing you what is used today. If you are comfortable with yours, then that's fine. But you don't need to typecast when allocating.
Anymore questions about memory allocation?