> Well, when I print the IP value, this is the result
> IP: 255.255.255.255fhv���
You don't append a \0 to the string you build up, so you get a random amount of trailing junk until the print function just happens to find a \0.

Also, your c variable should be an int if you want to compare it with EOF properly.
Consider this loop a simplification (and safer).
Code:
int c;
while ( i < 31 && (c=getc(fp)) != EOF && c != '\n' ) {
  dir[i++]=c;
}
dir[i] = '\0';
But this very near to what fgets() does for you anyway, so perhaps consider using that to read a line rather than inventing it yourself one character at a time.