The problem is that you are trying to reference your sample
variable as indexed as well as pointer . This will lead you to the wrong result.
while(sample[index] != '\0')
{
index++;
StringSample[index] = sample[index]; // indexed access
putchar(*sample++); // incrementing pointer sample.
}
You can simply achieve your goal as
#include <stdio.h>
int main()
{
char *sample = "From whence cometh my help?\n";
char *ptr = sample; // Saving the value of sample
while(putchar(*sample++))
;
putchar('\n');
sample = ptr; // Restoring sample's value.
puts(sample);
return(0);
}