home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19402 < prev    next >
Encoding:
Text File  |  1993-01-08  |  1.7 KB  |  54 lines

  1. Xref: sparky comp.lang.c:19402 comp.lang.c++:18826
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!uicvm.uic.edu!u10139
  3. Organization: University of Illinois at Chicago
  4. Date: Thu, 7 Jan 1993 23:05:24 CST
  5. From: T J Furstenau <U10139@uicvm.uic.edu>
  6. Message-ID: <93007.230524U10139@uicvm.uic.edu>
  7. Newsgroups: comp.lang.c,comp.lang.c++
  8. Subject:    Dynamic Mem Help
  9. Lines: 43
  10.  
  11.     I hope someone on the net can help me with this problem.  I'm trying
  12. to teach myself C and while working on dynamic memory allocation, I've
  13. run into a problem with the 'calloc' function.  When I try to run the
  14. following code, taken straight from the 'help' example with the
  15. compiler,
  16.  
  17. #include <stdio.h>
  18. #include <alloc.h>
  19. #include <string.h>
  20.  
  21. int main(void)
  22. {
  23.     char *str = NULL;
  24.  
  25.     /* allocate memory for string */
  26.     str = calloc(10, sizeof(char));
  27.  
  28.     /* copy "Hello" into string */
  29.     strcpy(str, "Hello");
  30.  
  31.     /* display string */
  32.     printf("String is %s\n", str);
  33.  
  34.     /* free memory */
  35.     free(str);
  36.  
  37.     return 0;
  38. }
  39.  
  40. I get the following error message:
  41.  
  42. Error D:\BC\BIN\WORK\NONAME00.CPP 10: Cannot assign 'void near*' to
  43. 'char near*' in function main().
  44.  
  45. Any ideas in what I or my system are doing wrong?  Are my compiler options
  46. set wrong?  Any answers, here or mailed, would be greatly appreciated.
  47.  
  48.  
  49. ***************************************************************************
  50. *  T J Furstenau          | Your clever saying | Looking for a position   *
  51. *  Grad May 92 BS-Math/CS |  could fill this   | as a programmer.  Anyone *
  52. *  U10139@UICVM.UIC.EDU   |      space         | hiring?                  *
  53. ***************************************************************************
  54.