Q:

Weird characters while getting str from a file in C

I tried to get the file's content and put it into a string. When I run my program and I print the string I get the file's content with some weird characters afterward.
My code:
int size = 0;
char ch = 0;
char* content = 0;
FILE* fs = fopen(file, "r");
//getting file's content and put it into a string
while (ch != EOF)
{
    ch = (char)fgetc(fs);
    size++;
    content = myRealloc(content, size);
    content[size - 1] = ch;
} 
printf("%s", content);

myRealloc:
char* myRealloc(char* array, int size)
{
    char* temp = 0;
    temp = realloc(array, size * sizeof(char));
    return temp;
}

The file's content:
1,2,3,4
5,6,7,8
a,b,c,d
e,f,g,h

When I print:
1,2,3,4
5,6,7,8
a,b,c,d
e,f,g,h ²²²²ר─

A:

Add the null terminated character at the end:
int size = 0;
int ch = 0;
char* content = 0;
FILE* fs = fopen(file, "r");
//getting file's content and put it into a string
while ((ch = fgetc(fs)) != EOF)
{
    size++;
    content = myRealloc(content, size);
    content[size - 1] = (char)ch;
}
size++;
content = myRealloc(content, size);
content[size - 1] = '\0';
print("%s", content);

Edit: Also, as pointed out by @achal, you are trying to add the EOF character since when you read it you are already in the while loop. I modified my code accordingly.

A:

The statement ch = (char)fgetc(fs); in the loop also try to print EOF, which you shouldn't.
Just Replace that block of code with
while ( (ch = fgetc(fs)) != EOF) { /* fetch the char & check the condition */
      putchar(ch);
      size++;
      content = myRealloc(content, size);
      content[size - 1] = ch;
}
size++;
content = myRealloc(content, size);
content[size - 1] = '\0';
print("%s", content);

Also check the manual page of fgetc()  it returns int. So make ch type as int.
 int fgetc(FILE *stream);

Also print("%s", content); should be printf("%s", content); unless you didn't define print().
Finally & most importantly once job is done, don't forgot to free the dynamically allocated memory by calling free() function.

