Thread: Question

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    10

    Question

    I'm so confused! My code won't work right. I need it to print out the login name and it won't do that. It just prints out the password again. How do I go about printing out the login name??


    printf("\n\nPlease enter a login name: ");
    gets(temp);

    ERROR = 0;
    for(i=0; i<4; i++)

    if(strcmp(name[i], temp) == 0)
    {
    ERROR = 0;
    break;
    }
    if (ERROR == 0)
    { Decrypt(name[i-1]);
    printf("Username Found!\n");
    printf("Username: ");
    puts(name[i+1]);
    printf("Password: ");
    puts(name[i+3]);
    }
    else
    printf("Invalid Login Name");
    }

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    19

    Lightbulb easy

    change these 3 lines

    puts(name[i+1]);
    printf("Password: ");
    puts(name[i+3]);

    to

    puts(temp[i+1]);
    printf("Password: ");
    puts(temp[i+3]);
    ~good monkeys, Excelent typewritters!...

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    10

    Well.

    Well, I already tried that and it gives me warnings of 'puts' being of different formats. So, it didn't work right.

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Hello,

    - What is the type of name?
    - I'm counting 5 brackets, perhaps one missing?

    Can you give more complete code.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    10

    More code...

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>

    #define NAME_LEN 50
    #define MAX 6
    #define ENCRYPTVAR 5

    int Valid(const char *nameptr);
    void Encrypt(char *word);
    void Decrypt(char *word);

    void main(void)
    {
    char name [MAX][NAME_LEN], temp [NAME_LEN];
    int i, j, ERROR;


    for(i=1; i<4; i++)
    {
    /*Prompt for 3 Usernames*/
    printf("Please Enter Login Name %d: ", i);
    gets(temp);

    /*Copy inputted string into name array*/
    for(j=0; temp[j] != 0; j++)
    {
    name[i-1][j] = temp[j];
    }
    name[i-1][j];
    }
    puts(" ");

    /*Prompt for 3 Corresponding Passwords*/
    printf("Please Enter Password 1: ");
    for(i=1; i<4; i++)
    { /*Enter Password and Check for Validity-If Valid Accept*/
    if( Valid( gets(temp)))
    {
    for(j=0; temp[j] != 0; j++)
    {
    name[i+2][j] = temp[j];
    }
    name[i+2][j] = 0;
    if(i+1 != 4)
    printf("Please Enter Password %d: ", i+1);
    }
    else
    {/*Make User Re-enter Valid Password*/
    i--;
    printf("Invalid Password, Please Re-enter: ");
    }
    }
    /*Encrypt Each Valid Password*/


    /*Print each Encypted Password*/
    {
    printf("Encrypted Passwords: ", i+1);
    puts("\n");
    Encrypt(name[3]);
    Encrypt(name[4]);
    Encrypt(name[5]);
    gets(temp);
    }

    /*Prompt for Username Search*/
    printf("\n\nPlease enter a login name: ");
    gets(temp);

    ERROR = 0;
    for(i=0; i<4; i++)

    if(strcmp(name[i], temp) == 0)
    {
    ERROR = 0;
    break;
    }
    if (ERROR == 0)
    { Decrypt(name[i-3]);
    printf("Username Found!\n");
    printf("Username: ");
    puts(name[i-1]);
    printf("Password: ");
    Decrypt(name[i-3]);
    puts(name[i]);
    }
    else
    printf("Invalid Login Name");
    }

  6. #6
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    1. You're storing the password in the same array as the names, so the names will be overwritten.

    2. Why not use standard string functions? Use strcpy for copying strings, strlen for determining the length, strncpy for copying just a part of a string etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM