Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed If I send password wrongly it need to send "password is incorrect"

0 votes
asked Sep 24, 2021 by TN CODER (280 points)
closed Oct 25, 2021 by Admin

If I send password wrongly it need to send  "password is incorrect".

My code: 

#include<>
#include<>

main() 
{
    char name, email, pass;
    printf("Enter your name: ");
    scanf("%c", &name);
    printf("Enter your email-id: ");
    scanf("%c", &email);
    printf("Enter password: ");
    scanf("%c", &pass);
    if(pass=abcd)
    {
        printf("Passoword is correct");
    }
    
    if else {
        printf("Password is incorrect");
    }
}

closed with the note: answered

1 Answer

0 votes
answered Sep 25, 2021 by Peter Minarik (55,660 points)
edited Sep 26, 2021 by Peter Minarik
 
Best answer

Below is your code fixed.

Legend

  • red: content removed
  • green: content added

The Code

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

int main() 
{
    char name, email, pass;
    char name[100]; // Strings ("text") is stored in char array or buffers.
    char email[100];
    char pass[100];
    printf("Enter your name: ");
    scanf("%c%s", name); // You want to read a whole string (%s), not just a single character (%c)
    printf("Enter your email address: ");
    scanf("%c%s", email);
    printf("Enter password: ");
    scanf("%c%s", pass);
    if(pass=abcd)
    if (strcmp(pass, "abcd") == 0) // strcmp() is used to find any differences between strings. 0 mean no difference.
    {
        printf("Passoword is correct.");
    }
    if else // The "if" must not be there.
    {
        printf("Password is incorrect.");
    }
}

References

commented Sep 25, 2021 by TN CODER (280 points)
Thank you, for your help :). Once again thank you very much :).
commented Sep 25, 2021 by TN CODER (280 points)
but it show's error in this code.

here:

    if else // The "if" mustbe bet there.
    {
        printf("Password is incorrect.");
    }

edit: Sorry I for got to take this extra "#include<>".
now it is working perfectly...
thank you very much :)
commented Sep 26, 2021 by Peter Minarik (55,660 points)
All good. I'm happy that you're sorted.
commented Sep 26, 2021 by TN CODER (280 points)
Ok :).   Good
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...