16 startFrom = startFrom > 0 ? startFrom : 0;
28 fh = fopen(
"HallOfShame.dat",
"r");
29 if (fh == NULL || ferror(fh)){
37 output(
"[ HALL OF SHAME ]\n\nWelcome to our Hall of Shame...\n");
40 int somethingPrinted =0;
41 while((fscanf(fh,
"%19[^,],%19[^,],%2[^,^\n]",victor,victim,moves)) != EOF ) {
43 while (victor[0] ==
'\n'){
44 memmove(victor, victor+1, strlen(victor));
46 if(lineCounter>=startFrom && lineCounter<=startFrom+
HOS_LINES && strlen(victor)>0 && strlen(victim)>0){
47 if(highlight==lineCounter){
48 output(
"-->%d. %s busted %s with %s moves\n",lineCounter+1,victor,victim,moves);
52 output(
" %d. %s busted %s with %s moves\n",lineCounter+1,victor,victim,moves);
60 if(somethingPrinted == 0){
65 output(
"[...Press up/down for scrolling...]\n");
66 output(
"[...Press Enter/Escape to exit...]\n");
72 startFrom = startFrom-1 > 0 ? startFrom-1 : 0;
75 startFrom = startFrom+1 < lineCounter-
HOS_LINES ? startFrom+1 : startFrom;
104 char* buffer = malloc((
getOldFileLength()+strlen(victor)+strlen(victim))*
sizeof(
char)+3);
105 int insertedLineNumber = 0;
113 fh = fopen(
"HallOfShame.dat",
"r");
115 while((fscanf(fh,
"%59[^\n]\n",line)) != EOF ) {
119 if(currentMoves <= moves){
121 strcat (buffer,line);
122 insertedLineNumber++;
125 char insertLine[120];
127 sprintf(insertLine,
"%s,%s,%d\n%s\n",victor,victim,moves,line);
128 strcat (buffer,insertLine);
133 strcat (buffer,line);
140 sprintf(lastLine,
"%s,%s,%d\n",victor,victim,moves);
141 strcat(buffer,lastLine);
147 fh = fopen(
"HallOfShame.dat",
"w");
152 return insertedLineNumber;
165 partOfLine = strtok(work,
",");
167 while(partOfLine != NULL) {
170 moves = atoi(partOfLine);
175 partOfLine = strtok(NULL,
",");
187 FILE *f = fopen(
"HallOfShame.dat",
"rb");
189 if (f == NULL || ferror(f))
196 fseek(f, 0, SEEK_END);
void showHallOfShame(int highlight, int startFrom)
const int EXITCODE_OUTOFMEMORY
void setLineAlign(int align)
void startBuffer(int maxTextLength)
int updateSaveHoS(char *victor, char *victim, int moves)
int extractMoves(char *line)
int output(const char *input,...)