Thread: username password

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    66

    username password

    How would i go about changing a string to uppercase, no matter what case the characters are entered in the program??


    Also how would i go about creating a username and password function?

    THanks.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    34
    tolower() and toupper() ignores the case as far as I know.

    Creating username and passwd: Which plattform, *nix or Windows ? In Unix you could prepare a string and use system() for it, which'd be the easiest way

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    66
    I'm using dev c++ on windows.

    Where would i put the toupper?

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    5
    Here is just a simple function I wrote:
    Code:
    void convertToUppercase(char *sPtr)
    {
        while (*sPtr != '\0') { // current character is not '\0'
    
              if(islower(*sPtr)) { //if character is lowercase
                   *sPtr = toupper(*sPtr); //convert to uppercase
              }
          ++sPtr //move sPtr (pointer to the next character
         } //end while
    } //end function convertToUppercase

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >How would i go about changing a string to uppercase, no matter what case the characters are entered in the program??
    toupper in <ctype.h>.

    >if(islower(*sPtr))
    This test is not needed anymore for a simple case switch. toupper is guaranteed to return its argument unchanged if there is no suitable conversion. So your function could be simplified even more (with my own embellishments):
    Code:
    char *stoupper ( char *s )
    {
      while ( *s != '\0' )
        *s++ = toupper ( *s );
    }
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    66
    Code:
    (/* DISPLAY DESIGNER NAMES */
    void f_display_designer ()
    {
    	 int num_i;
         num_of_items_i1 = 1;
    
    
    
    printf("______________________________________\n");
    printf("DESIGNER INFORMAION\n");
    printf("_______________________________________\n");
    printf("\n");
    
                      for (num_i = 0; num_i < num_of_items_i1; num_i ++);
    		{
    		printf ("%s     %s  %s     %s \n", designer[num_i].forename_s, designer[num_i].surname_s, designer[num_i].mobile_number_s, designer[num_i].area_s );
    
    	
    		printf("__________________________________\n\n\n\n\n");
    		}


    thats an example of my display code where would i add the peice of code?

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    If you want all output in upper case:
    Code:
    printf ("%s     %s  %s     %s \n",
      stoupper ( designer[num_i].forename_s ),
      stoupper ( designer[num_i].surname_s ),
      designer[num_i].mobile_number_s,
      designer[num_i].area_s );
    My best code is written with the delete key.

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    66
    Do i not need this part >>>
    Code:
    char *stoupper ( char *s )
    {
      while ( *s != '\0' )
        *s++ = toupper ( *s );
    }
    ??

  9. #9
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    of course you do

  10. #10
    Registered User
    Join Date
    Mar 2004
    Posts
    66
    Great, where do i put it?

  11. #11
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    In the C Standard library, there are functions strupr() and strlwr() that convert strings to all-upper or all-lower case. The conversion is in-place (it modifies the original string).

    Why not try one of these?

    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
      char string1[] = "This is string #1";
      char string2[] = "This is string #2";
      char string3[] = "This is string #3";
    
      printf("Initial Strings:         <%s> <%s> <%s> \n\n", 
               string1, string2, string3);
    
      printf("Strings using functions: <%s> <%s> <%s> \n\n", 
              strupr(string1), strlwr(string2), string3);
    
      printf("Strings after functions: <%s> <%s> <%s> \n", 
              string1, string2, string3);
    
      return 0;
    }
    Dave

  12. #12
    Registered User
    Join Date
    Mar 2004
    Posts
    5
    On the top, before int main(), or you can take it at the boun, and make a prototype at the global declare place, where you include headers/libaries etc.. Should look like this:
    char *stoupper(char *s); //prototype
    Then you can use it as much you want

  13. #13
    Registered User
    Join Date
    Mar 2004
    Posts
    66
    Cheers Dave that works a treat.

  14. #14
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Why not try one of these?
    Because despite being in string.h on your compiler, they actually are not a part of the standard library.
    My best code is written with the delete key.

  15. #15
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Originally posted by Prelude
    >Why not try one of these?
    Because despite being in string.h on your compiler, they actually are not a part of the standard library.



    [edit]

    Oops: now I see: string.h is in the standard; not strupr(), strlwr().
    (But they are in Borland, Microsoft VC++, GNU gcc libraries, and I've used them from time to time).

    Apologies, and thanks for the information
    [/edit]
    Dave
    Last edited by Dave Evans; 03-14-2004 at 05:53 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A tenet connection from a C program..
    By ahmd2080 in forum Linux Programming
    Replies: 2
    Last Post: 07-04-2009, 03:42 AM
  2. Read from file and match the password and username
    By plodos in forum C Programming
    Replies: 3
    Last Post: 01-05-2009, 01:10 PM
  3. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 03:42 AM
  4. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  5. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 12:14 AM