From 935a6ae3c1d2bb70bfa5e0749188acee0988642a Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Tue, 2 Apr 2024 18:32:37 +0200 Subject: Reformatted PositionFilePtr() --- FICS/ratings.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/FICS/ratings.c b/FICS/ratings.c index 5ea446f..2b8f459 100644 --- a/FICS/ratings.c +++ b/FICS/ratings.c @@ -1080,29 +1080,34 @@ PRIVATE int GetRank(FILE * fp, char *target, int countComp) return (playerFound ? count : -1); } -PRIVATE void PositionFilePtr(FILE * fp, int count, int *last, - int *nTied, int showComp) +PRIVATE void +PositionFilePtr(FILE *fp, int count, int *last, int *nTied, int showComp) { - int i, rating, nGames, is_computer; - char login[MAX_LOGIN_NAME]; - char line[MAX_RANK_LINE]; + char line[MAX_RANK_LINE] = { '\0' }; + char login[MAX_LOGIN_NAME] = { '\0' }; + int rating, nGames, is_computer; - if (fp == NULL) - return; - rewind(fp); - for (i = 1; i < count; i++) { - do { - fgets(line, MAX_RANK_LINE - 1, fp); - if (feof(fp)) - break; - sscanf(line, "%s %d %d %d", login, &rating, &nGames, &is_computer); - } while (!CountRankLine(showComp, login, nGames, is_computer)); - if (rating != *last) { - *nTied = 1; - *last = rating; - } else - (*nTied)++; - } + if (fp == NULL) + return; + + rewind(fp); + + for (int i = 1; i < count; i++) { + do { + fgets(line, MAX_RANK_LINE - 1, fp); + + if (feof(fp)) + break; + sscanf(line, "%s %d %d %d", login, &rating, &nGames, + &is_computer); + } while (!CountRankLine(showComp, login, nGames, is_computer)); + + if (rating != *last) { + *nTied = 1; + *last = rating; + } else + (*nTied)++; + } } PRIVATE int -- cgit v1.2.3