Thread: Problem I can't seem to solve

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    3

    Problem I can't seem to solve

    Hello all

    I've got an assignment to make a quiz.
    First of all one must be able to create users with a passwords
    when the program starts, it ask if you want to create a user/pass or login


    creating I've done... it writes all the users to a file
    both username and password are max 15 long...
    they are written to a binary file :

    ----15 for username----- 15 for pasword----- (without the trails.. it's just white spaces)


    now when I want to test my login. i've got a problem:

    I first ask the user to enter pass en login
    I save this but the watch of my compiler tells me it just saved what I write and not the 15 long

    so during the stringcompare it's logical it doesn't compare:

    more info on the script:

    let's imagine i enter user1 and pass1
    and that inside the file it says user1 and pass1:

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <conio.h>
    
    
    int login(void){
    
    char user[15];
    char pass[15];
    char temp_user[17];
    char temp_pass[17];
    int sw_ok=1;
    FILE *login;
    
    clrscr();
    printf("\t**********************************************\n");
    printf("\t*                  Login                     *\n");
    printf("\t**********************************************\n");
    
    while (sw_ok)
    {
    login=fopen("users.dat", "rb");  
    printf("username: ");
    scanf("%15s", user); //according to watch it store "user1"
    printf("Paswoord: ");
    scanf("%15s", pass);  //according to watch it stores "pass1"
    
    
    while(!feof(login))
    {
    	 fgets(temp_user,sizeof(user)+1,login); //gets "          user1"
    	 fgets(temp_pass,sizeof(pass)+1,login); //gets "         pass1"
    	
    
    		if (strcmp(temp_user, user) == 0 && strcmp(temp_pass, pass) ==0) {
    			printf("\nAccess OK\n");
    			sw_ok=0;
    			}
    		else printf("\incorrect\n");
    
    }
    
    
    
    }
    printf("Tataaaa");
    return 0;
    }


    thanks for some feedback...
    Last edited by psykik; 05-15-2005 at 03:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Solve This Problem Within 3 Hr Urgent Need
    By annum in forum C Programming
    Replies: 12
    Last Post: 10-04-2009, 09:56 AM
  2. problem solve
    By coolnarugodas in forum C Programming
    Replies: 7
    Last Post: 04-26-2005, 12:31 PM
  3. Replies: 2
    Last Post: 04-25-2005, 11:59 AM
  4. Bubble Sort / selection problem
    By Drew in forum C++ Programming
    Replies: 7
    Last Post: 08-26-2003, 03:23 PM
  5. problem cant solve please help.
    By sarah in forum C Programming
    Replies: 6
    Last Post: 09-03-2001, 01:32 PM