-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.c
71 lines (62 loc) · 1.12 KB
/
files.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
extern int errno;
FILE *fp = NULL;
int dofileexist(char* filename)
{
fp = fopen(filename, "r");
return errno;
fclose(fp);
}
void register_user(char* nickname, char* password)
{
fp = fopen(nickname, "aw");
fprintf(fp, "%s",password);
fclose(fp);
}
int check_login_data(char* nickname, char* password)
{
fp = fopen(nickname, "r");
char pass[256];
fscanf (fp, "%s", pass);
// printf("%s", pass);
fclose(fp);
return strncmp(pass, password, 256);
}
int is_anybody_logged_in(char* user)
{
char* guest = "Gość";
int test = strncmp(user, guest, 256);
if (test != 0)
{
return 1;
}
else
{
return 0;
}
}
void push_to_hiscores(char* user, int score)
{
fp = fopen("hi.scores", "aw");
fprintf(fp, "%s|%d\n",user, score);
fclose(fp);
}
void print_hiscores()
{
fp = fopen("hi.scores", "r");
int i=0;
printf("Hiscores:\n");
printf("-------------------------------\n");
char dane[256];
while(!feof(fp))
{
fscanf (fp, "%s ",&dane);
printf("|\t%s\t|\n",dane);
i++;
}
printf("-------------------------------\n\n\n");
fclose(fp);
}