-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRequests.c
More file actions
65 lines (63 loc) · 1.37 KB
/
Requests.c
File metadata and controls
65 lines (63 loc) · 1.37 KB
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
void Requests(char namefromfunction[20])
//Checks for friends requests
{
int fdecision;
FILE *acceptor;
FILE *sender;
FILE *request;
request=fopen("tempr.txt", "w");
if (request==NULL)
printf("File not opened.\n");
fclose(request);
char temp[20], X[20], C[20];
int count=0;
strcpy(X, namefromfunction);
char *check=strcat(X,"request.txt");
request=fopen(check,"r+");
count=0;
while(!feof(request))
{
fscanf(request,"%s",C);
count++;
}
count=count/2;
//printf("%d",count);
rewind(request);
//printf("%d",count);
while(!feof(request))
{
if(count==0)
{
printf("No friend requests!\n\n");
break;
return;
}
fscanf(request,"%s",temp);
printf("%s sent you a friend request?\nDo you want to be his friend?\n1.Yes\n2.No\n",temp);
scanf("%d",&fdecision);
if(fdecision==1)
{
char N[20];
FILE *sender;
char S[20];
FILE *add;
strcpy(N,namefromfunction);
char *accept=strcat(N,".txt");
add=fopen(accept,"a+");
fprintf(add,"%s\n", temp);
fclose(add);
strcpy(S, temp);
char *sent=strcat(S,".txt");
sender=fopen(sent, "a+");
fprintf(sender, "%s\n",namefromfunction);
fclose(sender);
}
count--;
if(count==0)
break;
}
fclose(request);
remove(check);
rename("tempr.txt", check);
Exist(namefromfunction);
}