#include <stdio.h>
#include <string.h>
int
main() {
FILE
* user_file =
fopen
(
"2b_user_list.txt"
,
"r"
);
if
(user_file == NULL) {
perror
(
"Error opening user file"
);
return
1;
}
char
line[100];
char
valid_users[100][20];
int
valid_user_count = 0;
while
(
fgets
(line,
sizeof
(line), user_file)) {
line[
strcspn
(line,
"\n"
)] =
'\0'
;
strcpy
(valid_users[valid_user_count], line);
valid_user_count++;
}
fclose
(user_file);
FILE
* cad_file =
fopen
(
"cad2023_2b_w8.txt"
,
"r"
);
if
(cad_file == NULL) {
perror
(
"Error opening CAD file"
);
return
1;
}
char
unique_users[100][20];
int
unique_user_count = 0;
while
(
fgets
(line,
sizeof
(line), cad_file)) {
char
* token =
strtok
(line,
" "
);
if
(token != NULL &&
strstr
(token,
"cad"
) == token) {
char
student_number[20];
strcpy
(student_number, token + 3);
int
is_valid = 0;
for
(
int
i = 0; i < valid_user_count; i++) {
if
(
strcmp
(valid_users[i], student_number) == 0) {
is_valid = 1;
break
;
}
}
if
(is_valid) {
int
is_duplicate = 0;
for
(
int
i = 0; i < unique_user_count; i++) {
if
(
strcmp
(unique_users[i], student_number) == 0) {
is_duplicate = 1;
break
;
}
}
if
(!is_duplicate) {
strcpy
(unique_users[unique_user_count], student_number);
unique_user_count++;
}
}
}
}
for
(
int
i = 0; i < unique_user_count / 2; i++) {
char
temp[20];
strcpy
(temp, unique_users[i]);
strcpy
(unique_users[i], unique_users[unique_user_count - 1 - i]);
strcpy
(unique_users[unique_user_count - 1 - i], temp);
}
for
(
int
i = 0; i < unique_user_count; i++) {
printf
(
"%s\n"
, unique_users[i]);
}
fclose
(cad_file);
return
0;
}