Please Help me. Nothing being Printed probably Pointer mistake

So I was programming C in one of the lessons and nothing is being printed to the console. Please help. Here is my code. No errors are coming up!


void copy(char* dst, char* src){
while(src != “\0”)
*dst = *src;
*dst = 0;

int main(){
char srcString = “We promptly judged antique ivory buckles for the next prize!”;
int l = strlen(srcString);
char dstString[l];
char *srcPtr = &srcString[0];
char *dstPtr = &dstString[0];
copy(dstPtr, srcPtr);
dstPtr = &dstString[0];
for(int i = 0; i < strlen(dstString); i++)
printf(“%c”, *dstPtr);

Hey @soontobetoptierprogr!

Hope you got it, the reason why it didn’t work is because you need to dereference the pointer src in your while statement because otherwise it only has the address of the char, you need to dereference it to get the actual char. Also, \0 should be wrapped in '' for chars because it is represents the zero constant character, (which is actually just the int 0), so all together…

while (*src != '\0')  {

Also, an array is a collection of data stored in contiguous places in memory. In c, an array points to the first element of the array. To get to the other elements, it just adds however many bytes the element is to get to the next element, but it seems you already know that based on your code . So, instead of doing &srcString[0] you could just do srcString, and same with the others, but it’s all up to you :slight_smile:


Now I feel humbled. Thank you very much such a simple mistake but I for the life of me couldn’t find it. I was using the [0] method as I just learned it and wanted to it’s use. Of course [0] is practically reduantant.
All in all thanks for the constructive feedback. Have a nice day. :grinning:

I understand the feeling, just remember it’s all part of the learning process and coding in general (even professionals do), I experience it as well. It’s always good to want to use what you learned, so no worries. Also thanks, I am glad I could be of help! Hope you have a nice day as well! :smile:

1 Like


I was actually looking back on the solution, and I realized I made a mistake in something I said. Even though I did say you could do srcString, there is a difference between both. I had come across this (you only need to read the first part of Joe’s answer):

With this in mind, I think the way you did it is the correct way than what I had proposed.

My apologies!

Thank you, for taking your time to do some more research on it. So one is for pointers and one for the array variable itself.

Exactly that I believe, and no problem.