#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char *argv[]) {
FILE *fp_user;
FILE *fp_password;
FILE *fp_location;
FILE *fp_data;
char str_user [1024];
char str_password [1024];
char str_location [1024];
if (argc != 3) {
perror ("Wrong Number of Arguments!");
exit(-2);
}
if ((fp_user = fopen ("/home/david/user.txt", "r")) == NULL) {
perror ("Can't open file");
exit (-1);
}
if ((fp_password = fopen ("/home/david/passwords.txt", "r")) == NULL) {
perror ("Can't open file");
exit (-1);
}
if ((fp_location = fopen ("/home/david/location.txt", "r")) == NULL) {
perror ("Can't open file");
exit (-1);
}
while (!feof(fp_user) && (!feof(fp_password)) && (!feof(fp_location))) {
fscanf (fp_user, "%s", str_user);
fscanf (fp_password, "%s", str_password);
fscanf (fp_location, "%s", str_location);
if (strcmp (str_user, argv[1]) == 0) {
if (strcmp (str_password, argv[2]) == 0) {
if ((fp_data = fopen (str_location, "r")) == NULL) {
perror ("Can't open file");
exit (-1);
}
while (!feof(fp_data)) {
putc (fgetc(fp_data), stdout);
}
fclose (fp_data);
fclose (fp_location);
fclose (fp_password);
fclose (fp_user);
exit (0);
}
else {
if ((fp_data = fopen ("/home/david/wrongpassword.jpg", "r")) == NULL) {
perror ("Can't open file");
exit(-1);
}
while (!feof(fp_data)) {
putc (fgetc(fp_data), stdout);
}
fclose (fp_data);
fclose (fp_location);
fclose (fp_password);
fclose (fp_user);
exit (0);
}
}
}
if ((fp_data = fopen ("/home/david/wrongpassword.jpg", "r")) == NULL) {
perror ("Can't open file");
exit(-1);
}
while (!feof(fp_data)) {
putc (fgetc(fp_data), stdout);
}
fclose (fp_data);
fclose (fp_location);
fclose (fp_password);
fclose (fp_user);
exit (0);
}