This is supposed to be a basic programme to see how malloc works, it compiles and runs giving the correct output but then I get "DEBUG error, heap corruption detected" and I don't understand what I've done wrong.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *p;
p = (char *)malloc(sizeof(char));
if (p==0)
{
printf("\nERROR. Not enough memory\n");
return 1;
}
else{
printf("\nEnter your six digit library card no. \n");
scanf("%s", p);
printf("value = %s\n", p);
free(p);
}
return 0;
}