help fast T.T

This is a discussion on help fast T.T within the C Programming forums, part of the General Programming Boards category; 1how to type the code for a log in function? descriptions: to enable librarian to log in. all the username ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    16

    help fast T.T

    1how to type the code for a log in function?
    descriptions: to enable librarian to log in. all the username and password of the librarian of the librarian is store in file called ''librarian_id.txt''.


    *the code must include printf invalid format if user input invalid format.
    *my learnt topic is ...function, making decision, repetition, text input/output, arrays and strings.
    *the code should use this few topics only and not go to far.
    Last edited by yrhc@eht; 08-16-2008 at 09:45 PM. Reason: correct

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,980
    Please refer to our homework policy and edit your post accordingly.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    16

    laserlight

    Quote Originally Posted by laserlight View Post
    Please refer to our homework policy and edit your post accordingly.
    ok, laserlight, are you online now, then can you become my tutor? i will ask you step by step, i have tried myself many times, but really cant get, please. my deadline is next week.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,980
    can you become my tutor?
    Yes I can, but no, I will not become your tutor, unless you happen to be in my university and in a tutorial class that I happen to teach.

    i will ask you step by step, i have tried myself many times, but really cant get, please.
    Good to hear that you have tried. So what you should do is attempt the first step, and then post what you tried (including code) and how your attempt failed.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Aug 2008
    Posts
    16

    thanks

    Quote Originally Posted by laserlight View Post
    Yes I can, but no, I will not become your tutor, unless you happen to be in my university and in a tutorial class that I happen to teach.


    Good to hear that you have tried. So what you should do is attempt the first step, and then post what you tried (including code) and how your attempt failed.

    haha, ok ok, can we chat in msn? i am willing to learn yrhc_eht@yahoo.com.cn
    Last edited by yrhc@eht; 08-17-2008 at 03:13 AM.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,980
    Use this forum.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Jul 2008
    Posts
    133
    Wait a minute... I want laserlight as my tutor too... And i joined this forum before him !

  8. #8
    Registered User
    Join Date
    Aug 2008
    Posts
    16
    T.T nvm, ok

    *all the username and password of the librarian is stored in file called''Librarian_ID.txt"
    * Librarian_ID.txt
    --> Username (max length = 30 chars )
    --> Password ( max length = 30 chars )

    and below is a function to let me test is it work.
    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    void librarian_module ( );
    
    int main ( void )
    {
    	FILE* lib_login_pass;
    	char username [ 9 ];
    	char password [ 9 ];
    	char lib_username [ 9 ];
    	char lib_password [ 9 ];
    
    	lib_login_pass = fopen("Librarian_ID.txt", "r" );
    	if ( !lib_login_pass)
    	{
    		printf("Could not open file\a\n" );
    		exit (101);
    	}
    
    	printf("Please enter the following:  \n");
    	printf("Username: ");
    	scanf(" %s", username);
    	printf("Password: ");
    	scanf(" %s", password);
    
    	while ( fscanf ( lib_login_pass, " %s %s", lib_username, lib_password ) == 2 )
    	{
    		if  ( username == lib_username ) 
    		{
    			if  ( password == lib_password )
    			{
    				librarian_module ( );
    				break;
    			}
    		}
    		else
    			printf("Wrong username or password!\n");
    	}
    	return 0;
    }
    
    void librarian_module ( )
    {
    	printf("successful\n");
    	return;
    }
    Last edited by yrhc@eht; 08-17-2008 at 03:38 AM.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,980
    That's a step in the right direction, especially since your code is well indented with descriptive variable and function names. You also need to tell us what you expected it to do, and how does it not work.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Aug 2008
    Posts
    16
    it does not work, even though i type the correct username and password.

    in my librarian_ID.txt:

    qwertyu 1234567
    abcdefg 7654321

    can you tell me where is wrong or do i need use others like fgets, fget, sscanf...

  11. #11
    Registered User
    Join Date
    Jul 2008
    Posts
    133
    Use strcmp() instead of '==' to compare strings...

  12. #12
    Registered User
    Join Date
    Aug 2008
    Posts
    16
    can you give me an example?

  13. #13
    Registered User
    Join Date
    Jul 2008
    Posts
    133
    Quote Originally Posted by yrhc@eht View Post
    can you give me an example?
    Code:
    if (strcmp(username, lib_username) == 0)
    {
        // MATCH
    }
    (use strcasecmp() for case-insensitive compare)

    EDIT: in case 'username' contains '\n' char, use 'n' version:
    Code:
    strncmp(username, lib_username, strlen(username)-1)
    to compare (len-1) chars (ignore newline)
    Last edited by rasta_freak; 08-17-2008 at 03:50 AM.

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,980
    (use strcasecmp() for case-insensitive compare)
    Note that strcasecmp() is non-standard, though easy to implement with tolower() or toupper().
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    Registered User
    Join Date
    Jul 2008
    Posts
    133
    Quote Originally Posted by laserlight View Post
    Note that strcasecmp() is non-standard, though easy to implement with tolower() or toupper().
    Do you maybe know if/where it is called "stricmp"? I know i saw it somewhere but can't remember...

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 02-27-2009, 03:43 PM
  2. Saving a part of screen into a file fast!
    By Zap in forum C++ Programming
    Replies: 4
    Last Post: 06-28-2003, 10:56 AM
  3. Super fast bilinear interpolation
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 06-18-2002, 09:35 PM
  4. moving a bitmap, fast and smooth
    By werdy666 in forum Game Programming
    Replies: 1
    Last Post: 05-31-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21