Added Highscore interface
This commit is contained in:
parent
e253025cfd
commit
dcceccb571
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,14 +1,11 @@
|
|||||||
# git ls-files --others --exclude-from=.git/info/exclude
|
# git ls-files --others --exclude-from=.git/info/exclude
|
||||||
# Lines that start with '#' are comments.
|
# Lines that start with '#' are comments.
|
||||||
# For a project mostly in C, the following would be a good set of
|
|
||||||
# exclude patterns (uncomment them if you want to use them):
|
|
||||||
*.depend
|
*.depend
|
||||||
*.cbp
|
*.cbp
|
||||||
*.layout
|
*.layout
|
||||||
sdl2-config
|
sdl2-config
|
||||||
*.exclude
|
*.exclude
|
||||||
*.o
|
*.o
|
||||||
highscoretest.c
|
|
||||||
*.psd
|
*.psd
|
||||||
*.exe
|
*.exe
|
||||||
!bhi.exe
|
!bhi.exe
|
||||||
|
67
highscores.c
Normal file
67
highscores.c
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "highscores.h"
|
||||||
|
|
||||||
|
User * HIGHSCORES_GetList(int * usercount){
|
||||||
|
printf("Call BHI interface:\n");
|
||||||
|
system("bhi top output.txt");
|
||||||
|
printf("BHI interface quit!\nBHI output handling...\n");
|
||||||
|
|
||||||
|
FILE * fp;
|
||||||
|
char * line = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
ssize_t read;
|
||||||
|
char * name, * scorestring;
|
||||||
|
int nameCharCount = 0, scoreCharCount = 0;
|
||||||
|
bool switchread = false;
|
||||||
|
User * ul = malloc(10 * sizeof(User));
|
||||||
|
fp = fopen("output.txt", "r");
|
||||||
|
if (fp == NULL)
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
if ((read = getline(&line, &len, fp)) != -1)
|
||||||
|
if (line[0] == 0)
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
int counter = 0;
|
||||||
|
while ((read = getline(&line, &len, fp)) != -1) {
|
||||||
|
name = malloc(read * sizeof(char));
|
||||||
|
scorestring = malloc(read * sizeof(char));
|
||||||
|
nameCharCount = 0;
|
||||||
|
scoreCharCount = 0;
|
||||||
|
switchread = false;
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("Retrieved line of length %u:\n", read);
|
||||||
|
printf("%s", line);
|
||||||
|
#endif
|
||||||
|
for (ssize_t i = 0; i < read; i++) {
|
||||||
|
if (line[i] == '+') {
|
||||||
|
switchread = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (switchread) {
|
||||||
|
if (line[i] == '\n') break;
|
||||||
|
scorestring[scoreCharCount++] = line[i];
|
||||||
|
} else
|
||||||
|
name[nameCharCount++] = line[i];
|
||||||
|
}
|
||||||
|
name[nameCharCount] = '\0';
|
||||||
|
scorestring[scoreCharCount] = '\0';
|
||||||
|
User tmp;
|
||||||
|
tmp.Username = name;
|
||||||
|
tmp.Score = scorestring;
|
||||||
|
ul[counter++] = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
if (line)
|
||||||
|
free(line);
|
||||||
|
for (size_t i = 0; i < counter; i++) {
|
||||||
|
printf("User: %s -> Score: %s\n", ul[i].Username, ul[i].Score);
|
||||||
|
}
|
||||||
|
|
||||||
|
*usercount = counter;
|
||||||
|
printf("BHI Interface successfully quit!\n");
|
||||||
|
return ul;
|
||||||
|
} /* main */
|
10
highscores.h
Normal file
10
highscores.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef __highscores_h__
|
||||||
|
#define __highscores_h__
|
||||||
|
|
||||||
|
// Structs
|
||||||
|
typedef struct userStruct {
|
||||||
|
char * Username, * Score;
|
||||||
|
} User;
|
||||||
|
// End Structs
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user