I need to store five names of songs in memory using dynamic allocation and then print them to the screen.
What is wrong with my code?
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define MAXIM 5
void main() {
char song[30];
char *p;
p = (char*)calloc(MAXIM, sizeof(song) + 1);
for (int i = 0; i < MAXIM; i++) {
printf("Name of the song %d:\n", i);
scanf("%s", song);
strcpy(p[i], song);
};
for (int i = 0; i < MAXIM; i++) {
printf("%c\n", p[i]);
free(p[i]);
}
getch();
}