Firstly, malloc() and realloc() manage memory, not arrays. There is a difference. However, if you treat a pointer by returned by malloc() as if it was an array, then the compiler treats it that way as well. Array indices, like Java start at zero. So
If you want to compare strings, you do not use the comparison operators directly. You either compare one character at a time (in a loop) or use functions like strcmp() (declared in standard header <string.h>). This is because, by convention in C, a string is represented as an array of char, with a terminating char of value zero. So the string "end" is represented as four characters with values 'e', 'n', 'd', and '\0'. So, if array is an array of 4 char, and we want to stop if it contains the string "end". One way is
char *array = malloc(2); /* sizeof(char) is defined by the C standard to be 1 */
array = 'A';
array = 'B';
array = 'C'; /* invalid, but will not usually yield a compilation error. Result is undefined behaviour, which often manifests as a runtime error */
This is functionally equivalent to
while (!(array == 'e' && array == 'n' && array == 'd' && array == '\0')) ....
strcmp() is shorthand for "string comparison". It effectively implements a loop, comparing one character at a time.
while (strcmp(array, "end") != 0) ....
Also, when you malloc() or realloc(), YOU have to clean up the memory allocated. There is no garbage collection in C.
Another thing is that getchar() returns an int, and EOF is a value of type int that cannot be represented in a char. That means the type of ch needs to be int, not char .... otherwise a loop of the form while (ch != EOF) will never end.
At this stage, any basic textbook on C will get you started. However, I recommend VERY strongly that you try to put Java out of your mind while learning C. C does things very differently than Java, even if sometimes the code looks similar. You will waste a lot of time and effort, unnecessarily, if you keep thinking in terms of how you do things in Java first, and then map to C.