This is a good example of how NOT to do things. It starts with a typo in the essential word in the title of your post. The code you presented here has no reasonable indenting. And foremost, you are demonstrating bad programming techniques. There are easier methods of finding the length of a file than doing a character-by-character loop over its contents. If you had used one of those, you wouldn't have run into your problem in the first place.
The code in
if(size > 0)
{
while (fscanf(fp, " %s %d", ip, &port) > 0)
{
MessageBox (NULL, "fscanf() Successful", "SUCCESS!",
MB_ICONINFORMATION);
}
}
could be much simpler. The outer if-construct is totally useless. Your while loop will cover the case that the file is emply anyway. So, there is actually no need to determine the file length in the first step.
If it took you just 20 minutes to find the problem in your code, why did you post the question at all? I would have expected that you took so much thought
before even posting a question.