Thread: C sample help.

  1. #1
    Registered User
    Join Date
    Dec 2003

    C sample help.

    It's a sample program that asks for a username and password. After three guesses the program shuts down if all attempts are incorrect. The username is not supposed to be case sensitive; however, I can't seem to take case sensitivity off the username.

    It's just an assessment that tests my ability to make a user-defined function. It's not a major program. Can anyone help me take case sesitivity off the username?

  2. #2
    Registered User BillBoeBaggins's Avatar
    Join Date
    Oct 2003
    Change the given username and the acceptable username to uppercase or lowercase, then compare them.

    Look at this page...
    the function on the above page, strcmpi(), is probably in the string.h file.

    The first answer is what i would do if this function didn't exist.
    Last edited by BillBoeBaggins; 12-06-2003 at 04:27 PM.

  3. #3
    Registered User
    Join Date
    Nov 2003
    void noCase(char *s, int slen){
    	int i;
    	int c;
    		c = (int) *s;
    		if (c>96 && c<123){c = c - 32; *s = (char)c;};
    Here is an example with the code above

    char username[]="MyNaMe";

    Now username="MYNAME". The code makes everything be capitalized. For everything you do is for each character treat it as its capitalized. e.g. if you want to compare 2 strings. After the string when through my code it will all be capitalized. Then compare them.

    Hope that helps!

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > for(i=0;i<slen+1;i++)
    Why include the \0 at the end of the string?

    > (c>96 && c<123)
    Use islower(c)

    > c = c - 32
    Use toupper(c)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Phildelphia, PA
    Just convert everything to lowercase using the tolower() function found in <cctype>.

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sample Software Development Proposal ?
    By khpuce in forum A Brief History of
    Replies: 4
    Last Post: 03-24-2008, 09:38 AM
  2. Bjarne's member function binding sample is wrong?
    By George2 in forum C++ Programming
    Replies: 9
    Last Post: 03-11-2008, 04:05 AM
  3. MSDN volatile sample
    By George2 in forum C++ Programming
    Replies: 38
    Last Post: 01-05-2008, 06:59 AM
  4. MSDN OLE DB Sample Provider entry point
    By George2 in forum C++ Programming
    Replies: 0
    Last Post: 07-21-2007, 07:30 AM
  5. looking for non-MFC based socket programming sample
    By George2 in forum Networking/Device Communication
    Replies: 1
    Last Post: 06-19-2006, 05:57 AM