delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/12/21/17:59:34

Date: Wed, 21 Dec 94 12:02:48 PST
From: Curtiss Cicco <1CMC3466 AT ibm DOT MtSAC DOT edu>
Organization: Mt. San Antonio College
Subject: Undeclared string variable
To: djgpp AT sun DOT soe DOT clarkson DOT edu

      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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019