/* Why is the cast (char *) needed for malloc, this is ansi c not old kernigan */
/* and richie but I get an error saying cannot convert void to char without the */
/* cast (borland compiler, win 95 operating system) */
#include<stdio.h>
#include<string.h>
#include<alloc.h>
#include<process.h>
#include<conio.h>
int main(void)
{
char *str; /* Character pointer */
/* malloc returns a pointer to a block of memory or NULL */
if ((str=(char *)malloc(6)) == NULL) /* mallocs returned pointer is void */
{ /* A void pointer can be assigned to a pointer variable of any object type */
printf("Not enough memory to allocate buffer\n");
exit(1);
}
strcpy(str, "Hello");
printf("String is %s\n", str);
free(str);
getch();
return 0;
}
/* Thanks guys */