Thread: C Login System

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 C Login System 

    → Cheap Animated Banners ←



    Zexillium's Avatar
    Join Date
    Dec 2011
    Posts
    2,780
    Thanks given
    1,174
    Thanks received
    1,155
    Rep Power
    3284
    Fixed
    New Discord is 'zexillium'
    ↓ PROUD SUPPORTER OF ↓

    Attached image

    --> See My Animated Banner Shop <--
    Reply With Quote  
     

  2. #2  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    23
    Posts
    3,415
    Thanks given
    7,254
    Thanks received
    1,938
    Rep Power
    3905
    Problem may be in your path to the file.
    Attached image
    Attached image
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work here!
    Reply With Quote  
     

  3. #3  

    → Cheap Animated Banners ←



    Zexillium's Avatar
    Join Date
    Dec 2011
    Posts
    2,780
    Thanks given
    1,174
    Thanks received
    1,155
    Rep Power
    3284
    Quote Originally Posted by arham 4 View Post
    Problem may be in your path to the file.
    Nah. I tried adding it like file = fopen(C":\\Users\\Bla\\BlaBla2\\Profile.txt"); but it didn't really change anything
    New Discord is 'zexillium'
    ↓ PROUD SUPPORTER OF ↓

    Attached image

    --> See My Animated Banner Shop <--
    Reply With Quote  
     

  4. #4  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    23
    Posts
    3,415
    Thanks given
    7,254
    Thanks received
    1,938
    Rep Power
    3905
    try
    Code:
    		if (file == NULL) {
    			printf("File could not be found!\n");
    			getchar();
    			getchar();
    			choice = 0;
    		} else {
    			...
    		}
    Attached image
    Attached image
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work here!
    Reply With Quote  
     

  5. #5  

    → Cheap Animated Banners ←



    Zexillium's Avatar
    Join Date
    Dec 2011
    Posts
    2,780
    Thanks given
    1,174
    Thanks received
    1,155
    Rep Power
    3284
    Quote Originally Posted by arham 4 View Post
    try
    Code:
    		if (file == NULL) {
    			printf("File could not be found!\n");
    			getchar();
    			getchar();
    			choice = 0;
    		} else {
    			...
    		}
    Same result. It's the bottom one that is giving the error btw.
    New Discord is 'zexillium'
    ↓ PROUD SUPPORTER OF ↓

    Attached image

    --> See My Animated Banner Shop <--
    Reply With Quote  
     

  6. #6  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    23
    Posts
    3,415
    Thanks given
    7,254
    Thanks received
    1,938
    Rep Power
    3905
    It's definitely something to do with directories then. Where did you place Profile.txt? If its in the root (the folder that has src/ in it, not inside src/), you have to do "./Profile.txt", otherwise it needs to be in the bin folder.
    Attached image
    Attached image
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work here!
    Reply With Quote  
     

  7. #7  
    Registered Member

    Join Date
    Oct 2011
    Posts
    2,084
    Thanks given
    0
    Thanks received
    1,043
    Rep Power
    3608
    i'm a beginner as well but i'll try my best.

    the code given is fine according to your query but i think it's missing some closing braces and a return statement. make sure the .txt file is in the same directory and don't get confused with "file could not be found" and "profile not found". you may get the second one even if the file exists according to your code.

    Code:
    #pragma warning (disable: 4996)
    #include <stdio.h>
    #include <stdlib.h>
    
    int main() {
            /*User Struct which is used in order to create a new profile with a name, password, key and potential new
            files (Created after the login)*/
            typedef struct User {
                    char name;
                    char password;
                    char key;
                    char files[];
            };
    
            struct User User2;
            FILE *file;
            FILE *open = 0;
            char openFile[100];
            int answer = 0, choice = 0, found = 0, i = 0;
    
            printf("Hello! Welcome to Final Project\n\n");
            while (choice == 0) {
            printf("Press (1) to login\n");
            printf("Press (2) to create a new account\n");
            printf("Your choice: ");
            scanf("%d", &answer);
            printf("\n");
            if (answer == 1) {
                    // Open the file for reading
                    file = fopen("Profile.txt", "r");
                    if (!file) {
                            printf("File could not be found!\n");
                            getchar();
                            getchar();
                            choice = 0;
                    }
                            //Load File
                            i = 0;
                            while (!feof(file) && !found) {
                                    ++i;
                                    fscanf(file, "%s\t%s", &User2.name, &User2.password);
                                    if (strcmp(&User2.name) == 0 && strcmp(&User2.password) == 0) {
                                            printf("Profile found (%d): %s %s\n", i, &User2.name, &User2.password);
                                            choice = 1;
                                            found = 1;
                                    }
                            }
                            if (!found) {
                                    printf("Profile not found!\n");
                                    printf("Try again.\n\n\n");
                                    choice = 0;
                            }
                            fclose(file);
            }
    }
    
    return 0;
    
    }
    Reply With Quote  
     

  8. #8  

    → Cheap Animated Banners ←



    Zexillium's Avatar
    Join Date
    Dec 2011
    Posts
    2,780
    Thanks given
    1,174
    Thanks received
    1,155
    Rep Power
    3284
    Quote Originally Posted by arham 4 View Post
    It's definitely something to do with directories then. Where did you place Profile.txt? If its in the root (the folder that has src/ in it, not inside src/), you have to do "./Profile.txt", otherwise it needs to be in the bin folder.
    C:\Users\Alexander\source\repos\Slutproject.c\Slut project.c (Without any spaces, idk why it does a space on the last one)
    New Discord is 'zexillium'
    ↓ PROUD SUPPORTER OF ↓

    Attached image

    --> See My Animated Banner Shop <--
    Reply With Quote  
     

  9. #9  
    Registered Member

    Join Date
    Oct 2011
    Posts
    2,084
    Thanks given
    0
    Thanks received
    1,043
    Rep Power
    3608
    did the above code fix the issue lol.
    Reply With Quote  
     

  10. #10  

    → Cheap Animated Banners ←



    Zexillium's Avatar
    Join Date
    Dec 2011
    Posts
    2,780
    Thanks given
    1,174
    Thanks received
    1,155
    Rep Power
    3284
    Quote Originally Posted by Omelete View Post
    did the above code fix the issue lol.
    There are no differences other than that the main {} ends in your code. I have all brackets too its just that I have more code down below, and then brackets end there. Same with return.
    New Discord is 'zexillium'
    ↓ PROUD SUPPORTER OF ↓

    Attached image

    --> See My Animated Banner Shop <--
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Basic Login System
    By DJ Dan in forum Website Development
    Replies: 6
    Last Post: 02-18-2009, 03:12 PM
  2. Free login system
    By AlexMason in forum Website Development
    Replies: 17
    Last Post: 01-17-2009, 05:55 PM
  3. I need help creating a login system
    By pookani222 in forum Application Development
    Replies: 7
    Last Post: 11-19-2008, 06:12 PM
  4. I need help create some sort of "login" system that sends to my email
    By pookani222 in forum Application Development
    Replies: 1
    Last Post: 10-10-2008, 01:08 AM
  5. PHP/MySQL Login System
    By Vegeta in forum Website Development
    Replies: 7
    Last Post: 06-23-2008, 07:22 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •