Code:
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
char* decipher(char* decipher);
char* cipher(char* cipher);
void menu(list* ptr);
list* add(char* bar[], list* ptr);
list* edit(char* bar[], list* ptr);
list* verify(char* foo[], list* ptr);
list* del(char* bar[], list* ptr);
void addToList(list* ptr, char* foo, char* poo, char* boo);
void printList(list* ptr);
//prototypes
#include"cipher.c"
#include"menu.c"
typedef struct list
{
char *user;
char *pass;
char *type;
struct list *next;
} list, node;
list* initializeList() {
char buffer[50];
node* initial;
node* ptr;
FILE* addUser = fopen("password.csv", "rt");
initial = (node*)malloc(sizeof(node));
if (addUser != NULL)
{
fgets(buffer, 50, addUser); //Initializes first node of list
initial->user = strtok(buffer, " ,");
initial->pass = strtok(buffer, " ,");
initial->type = strtok(buffer, "\n");
initial->next = NULL; //ready's addition of next node
ptr = initial;
while(!feof(addUser))
{
while(ptr->user != NULL)
ptr = ptr->next;
node* link = (node*)malloc(sizeof(node));
fgets(buffer, 50, addUser);
link->user = strtok(buffer, " ,");
link->pass = strtok(buffer, " ,");
link->type = strtok(buffer, "\n");
ptr->next = link;
}
}
fclose(addUser);
return initial;
}
int main(int argc, char* argv[]) {
printf("lolol");
list* linkList = initializeList();
char* choice = argv[1];
int i;
if (!strcmp("-menu", choice)){//If statement processes menu mode, if specified by user
menu(linkList);
printList(linkList);
free(linkList);
return (-1);
}
for (i = 2; i < argc; i++){
if (!strcmp(argv[i],"-menu"))//Determines if menu was incorrectly specified at command-line
{
printf("Syntax Error: -menu must be the first argument.\n");
return (-1);
}
}
if (!strcmp(choice, "-add"))
add(argv, linkList);
else if (!strcmp(choice, "-del"))
del(argv, linkList);
else if (!strcmp(choice, "-edit"))
edit(argv, linkList);
else if (!strcmp(choice, "verify"))
verify(argv, linkList);
else
{
printf("Syntax Error: possible arguments include -menu to enter menu-driven mode or,"
" -add, -del, -edit, or -verify followed by the entry arguments.\n");
return (-1);
}
printList(linkList);
free(linkList);
return 0;
}
list* add(char* array[], list* linkList){
node* ptr = linkList;
char *userCheck;
char *ciphered[3];
printf("How about here");
while (ptr->user != NULL)
{
userCheck = strdup(ptr->user);
userCheck = decipher(userCheck);
if (!strcmp(array[2], userCheck))
{
printf("Entry already exists"); //Checks if user is already present in the directory
return (-1); //Does not allow for more than one instance of the same name.
}
ptr = ptr->next;
}
ciphered[0] = strdup(cipher(array[2]));//Passes user, password and type to be ciphered
ciphered[1] = strdup(cipher(array[3]));
ciphered[2] = strdup(cipher(array[4]));
ptr = (node*)malloc(sizeof(node)); //creates new struct for contents to be added
addToList(ptr, ciphered[0], ciphered[1], ciphered[2]);
return linkList;
}
Any minor thoughts or things I could try would help as well.