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;
- llnode * makeLinkedList(){
- head = (llnode *)malloc( sizeof(llnode) );
- head -> username = NULL;
- head -> password = NULL;
- head -> usertype = NULL;
- head -> next = NULL;
- return head;
- }
- int loadToLinkedList(FILE *file){
- char * record = (char *)malloc(100*(sizeof(char)));
- 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, ",");
- pass = strtok(NULL, ",");
- type = strtok(NULL, "\n");
- addNode(name, pass, type);
- }
- fclose(file);
- }
- char * makeRecord(char * user, char * pass, char * type){
- char * buffer = (char *)malloc( 1000 );
- strcat(buffer, user);
- strcat(user, ",");
- strcat(user, pass);
- strcat(user, ",");
- strcat(user, type);
- return buffer;
- }
- int backToTheFile(llnode* head){ //like Back to the Future
- FILE *passwords = fopen("password.csv", "at");
- llnode *temp = (llnode *)malloc(sizeof(llnode));
- temp = head;
- temp = temp -> next;
- while (temp != NULL){
- char * record = makeRecord(temp -> username, temp -> password, temp -> usertype);
- fputs(record, passwords);
- temp = temp -> next;
- }
- fclose(passwords);
- }
- 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];
- makeLinkedList();
- loadToLinkedList(fopen("passwords.csv", "rt"));
- if (fopen("password.csv", "rt") == NULL){
- system("touch password.csv");
- }
- 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