Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "menu.c"
- char *record;
- typedef struct node {
- char *username;
- char *password;
- char *usertype;
- struct node * next;
- } llnode;
- llnode* head;
- llnode* makeLinkedList(){
- head = (llnode *)malloc( sizeof(llnode) );
- head -> username = NULL;
- head -> password = NULL;
- head -> usertype = NULL;
- head -> next = NULL;
- return head;
- }
- void addNode(char *username, char *password, char *usertype){
- llnode *addNode = (llnode *)malloc(sizeof(llnode));
- llnode * curNode = head;
- while (next -> next != NULL){
- curNode = curNode -> next;
- }
- next -> next = addNode;
- addNode -> username = username;
- addNode -> password = password;
- addNode -> usertype = usertype;
- addNode -> next = NULL;
- printf("%s , %s, %s", username, password, usertype);
- }
- void loadToLinkedList(FILE *file){
- char * record = (char *)malloc(100*(sizeof(char)));
- char *delims[] = {", " , "\n"};
- char *name;
- char *pass;
- char *type;
- while (!feof(file)){
- fgets(record, 99, file);
- //while the next line of the file isn't the end of file, assign that record's fields to the NODE struct
- name = strtok(record, &delims[0]);
- pass = strtok(NULL, &delims[0]);
- type = strtok(NULL, &delims[1]);
- addNode(name, pass, type);
- }
- fclose(file);
- }
- //int main(void){
- // FILE *file = fopen("password.csv", "rt");
- // makeLinkedList();
- // loadToLinkedList(file);
- // return 0;
- //}
- void backToTheFile(llnode* head){ //haha like Back to the Future
- FILE *passwords = fopen("password.csv", "wt");
- head = head -> next;
- while (head != NULL){
- char *record = makeRecord(head -> username, head -> password, head -> usertype);
- fputs(record, passwords);
- head = head -> next;
- }
- }
- char *makeRecord(char user[20], char pass[20], char type[20]){
- strcat(user, ", ");
- strcat(user, pass);
- strcat(user, ", ");
- strcat(user, type);
- char *record = user;
- return record;
- }
- int main(int argc, char *argv[]){
- int i;
- char* username = argv[2];
- char* password = argv[3];
- char* usertype = argv[4];
- char *user2 = argv[5];
- char *pass2 = argv[6];
- char *type2 = argv[7];
- char recordArray[50][50];
- makeLinkedList();
- loadIntoLinkedList(fopen("passwords.csv", "rt"));
- if (!strcmp(argv[1], "-menu")){
- menu(); //switch to menu mode
- }
- else{
- for (i = 0; i < argc; i++){
- if (argv[i] == "menu" && i != 1){
- printf("Error: the proper syntax for this command is $passweb -menu -add -del - edit -verify username password type user_2 pass_2 type_2. Please check your syntax and try again. \n");
- return 0;
- }
- }
- }
- if (strcmp(argv[1], "-add") == 0 || strcmp(argv[1], "-del") == 0 || strcmp(argv[1], "-edit") == 0 || strcmp(argv[1], "-verify") == 0){
- char *flagFound;
- for (i = 2; i < argc; i++){ //if there are any other flags present in addition to the one you want, return an error
- if (sscanf(argv[i], "-", flagFound)){
- printf("Error: the proper syntax for this command is $passweb -menu -add -del - edit -verify username password type user_2 pass_2 type_2. Please check your syntax and try again. \n");
- return 0;
- }
- }
- else if (strcmp(argv[1], "-add") == 0){
- add(username, password, usertype);
- }
- else if (strcmp(argv[1], "-del") == 0){
- delete(username);
- }
- else if (strcmp(argv[1], "-edit") == 0){
- edit(username, user2, pass2, type2);
- }
- else if (strcmp(argv[1], "-verify") == 0){
- verify(username, password);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement