I have a program that's attempting to use the strcpy()
function. I know that when one uses a char array such as: char array[10]
the null terminator can be set by: array[0] = '\0';
However, how would I go about setting the null terminator(s) when using char pointers?
EDIT: The program compiles, but gives garbage as output
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
char *target;
char *src = "Test";
target = malloc(sizeof(char));
src = malloc(sizeof(char));
strcpy(target,src);
printf("%c\n",target);
return 0;
}