Question

Write a code in C language to do following: 1. display pin input by user in...

Write a code in C language to do following: 1. display pin input by user in **** form instead of numbers by using ncurses 2. verify the pin by comparing with already stored 2 pins in a text file 3. change text color as per user choice

WINDOWS BASED

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//code for the problem

#include<stdio.h>
#include<conio.h>
#include<stdbool.h>
#include<windows.h>

HANDLE console_handle;                           //we will create a handle to our window

int gettextattribute(){                          
   CONSOLE_SCREEN_BUFFER_INFO buffer;           //object of console screen buffer
   GetConsoleScreenBufferInfo(console_handle,&buffer);
   return buffer.wAttributes;
}

void textcolor(int color){
   SetConsoleTextAttribute(console_handle, (gettextattribute() & 0xf0) |color);
                                               //this sets the console texr arrtribut to color  
}

void main(){
   char userid[8];                           //to make it easiar to understand i took a 8 digit user id
   printf("Enter your user id\n");
   scanf("%s",userid); //to defferentiate between different users
   char pass[30];
   int i=0,j;
   do{
       pass[i]=getch();                    //here getch() takes input till it takes
                                           //\r as input, which indicates that user hit enter.
if(pass[i]!='\r'){
printf("*");                    //we will print * corresponding to every input
}
i++;
   }while(pass[i-1]!='\r');
   pass[i-1]='\0';
   FILE *fl= fopen("abc.txt","r");           //open the file
   char data[50];
   bool flag;
   while(fgets(data,50,fl)!=NULL){           //reads file line by line
       //printf("%s",data);
       flag=false;
       for(j=0;j<8;j++){
           if(data[i]!=userid[i]){
               flag=true;                   //user id mismatch
               break;
           }  
       }
       if(!flag){
           for(j=0;j<i-1;j++){
               if(data[9+j]!=pass[j]){
                   flag=true;               //password mismatch
                   printf("\nincorrect password\n %d\n",j,i);
                   break;
               }
           }
       }
       if(!flag){
           textcolor(5);                   //to set text color
                                           //now consoles do not support inbuilt textcolor feature, so we have to create it manually
           _cprintf("\nCorrect Password\r\n");
           break;
       }
   }
}

//corresponding abc.txt file

11710548 aniket
11710549 nikita

Add a comment
Know the answer?
Add Answer to:
Write a code in C language to do following: 1. display pin input by user in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a code in C language to do following: 1. display pin input by user in...

    Write a code in C language to do following: 1. display pin input by user in **** form instead of numbers by using ncurses 2. verify the pin by comparing with already stored 2 pins in a text file 3. change text color as per user choice WINDOWS BASED

  • Write a C program as follows: Single source code file Requests the user to input two...

    Write a C program as follows: Single source code file Requests the user to input two integer numbers Requests the user to make a choice between 0 (add), 1 (subtract), or 2 (multiply) Declares three separate functions Uses a pointer to these three functions to perform the requested action Outputs the result to the screen Submit your program source code file to this assignment. Sample Output Enter first integer number: 15 Enter second integer number: 10 Enter Choice: 0 for...

  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

  • please answer correctly and follow the code structure given [JavaFX/ Exception handing and text I/O] 1....

    please answer correctly and follow the code structure given [JavaFX/ Exception handing and text I/O] 1. Write a program for the following. NOTE that some of these steps are not dependent on each other. Using methods is mandatory. Make sure to use methods where it makes sense. a. Ask the user for a series of integers entered from the keyboard. Use a sentinel value such as 999 to end the input process. If the entered values are not integers, throw...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • Topics: list, file input/output (Python) You will write a program that allows the user to read...

    Topics: list, file input/output (Python) You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing student...

  • I need this in Net beans and not Python. Part 1 - Pseudo-code Design and write...

    I need this in Net beans and not Python. Part 1 - Pseudo-code Design and write the pseudo-code for the following Problem Statement. Problem Statement A company gives its employees an that will provide one of 3 results based on the following ranges of scores: Score Message on Report 90-100 Special Commendation 70-89 Pass Below 70 Fail Design a single If-Then-Else structure using pseudo-code which displays one of these messages based a score input by a user. Be sure your...

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT