-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserlist.c
55 lines (50 loc) · 1.08 KB
/
userlist.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
#include "userlist.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char * findUser(char * name)
{
FILE * dosya;
dosya = fopen("userlist.txt", "r");
User temp;
while((fscanf(dosya, "%s", temp.IP) != EOF ) && (fscanf(dosya, "%s", temp.name) != EOF))
{
if(strcmp(temp.name, name) == 0)
{
char * returnIP =(char *) malloc((strlen(temp.IP)+1) * sizeof(char));
strcpy(returnIP, temp.IP);
return returnIP;
}
}
fclose(dosya);
return NULL;
}
char * findName(char * IP)
{
FILE * dosya;
dosya = fopen("userlist.txt", "r");
User temp;
while((fscanf(dosya, "%s", temp.IP) != EOF ) && (fscanf(dosya, "%s", temp.name) != EOF))
{
if(strcmp(temp.IP, IP) == 0)
{
char * returnName =(char *) malloc((strlen(temp.name)+1) * sizeof(char));
strcpy(returnName, temp.name);
return returnName;
}
}
fclose(dosya);
return NULL;
}
void printAll()
{
FILE * dosya;
dosya = fopen("userlist.txt", "r");
User temp;
int i=0;
while((fscanf(dosya, "%s", temp.IP) != EOF ) && (fscanf(dosya, "%s", temp.name) != EOF))
{
printf("%d %s\n",++i, temp.name);
}
fclose(dosya);
}