You increase ptr, therefore, change the address to which it points. You cannot do this.
In your case, specify a separate pointer, say char * p = ptrand perform your operations with p, leaving ptrintact so that you can free(ptr)later.
EDIT , , ptr++, . ptr[i], ptr, ptr[i] ( ) .
(ptr++), .
, :
int main(int argc, char *argv[]){
char *ptr = NULL;
char * p;
ptr = (char *) malloc(LEN+1);
p = ptr;
strcpy(ptr, "hello");
int i = 0;
while (*p)
{
printf("ptr[%d] = %c\n", i++, *p);
p++;
}
free(ptr);
return 0;
}