I am new to C and have written a simple program ( added below) that receives a string allocates address to a pointer
allocates memory to the string accordingly and is supposed to print the string. I think I did everythig right so why does it print garbage instead of the string ???
ptr = str;
printf("Please enter a string >:");
ptr = (char*)malloc(strlen(ptr)+1);
if(ptr == NULL)
printf("memory allocation failure");