Mail Archives: djgpp/1994/12/21/17:59:34
In this C book I am working through, I've come to some code that
won't compile. I get an error msg saying 'str' is undeclared, here's the
code that is giving me problems:
------------------------------------------------------------------------
#include <stdlib.h>
main()
{
/* allocate memory for a 100 character string */
char *string;
if (( str = (char *) malloc(100)) == NULL)
{
printf( "Not enough memory to allocate buffer\n");
exit(1);
}
printf( "String was allocated!" );
return 0;
}
------------------------------------------------------------------
I also included malloc.h to see if that would work, but it didn't.
Is there something I am failing to include that is keeping the code
from compiling?
-CmC
- Raw text -