char *myfgets(char *s, int n, FILE *in) {
    char ch;
    if (n<=0) {
        return s;
    }
    while (((ch = getc(in)) != '\n')) {
        if(ch == EOF){
            return NULL;
        }
        else if (ch == '\n') {
            break;
        } else {
            *s=ch;
            s++;
        }
    }
    *s = '\n';
    if (ferror(in) != 0) {
        return NULL;
    } else {
        return s;
    }   
    
    if (strlen(s) > 512) {
        return NULL;
    }
}
I want to take 1 line only from some specific file and put the line into the char pointer (*s). I made this function but when I run the program it didn't work really well. For the result, there are a lot of unknown characters that are displayed.
Is there anything wrong with my code?
 
     
    