A 4 digit pin using pass by reference i n c

0 votes
asked Mar 8, 2019 by Kyle (200 points)
  1. Has to be used using pass by reference 
  2. Need to get the user to enter a 4 digit pin
  3. Must be passed to another function
  4. Then passed back from the function in an array
  5. Can't enter a number greater than 9
  6. Error check in case of a character being entered 

1 Answer

0 votes
answered Apr 2, 2019 by sriteja (180 points)
#include<stdio.h>
char *input(char *p) //collecting array with char pointer
{
   input: scanf("%s",p);//reading input
    if(check(p)) //checking if any alphabets are present in the password
    {
        printf("enter only digits\n");
        goto input;
    }
    return p;
}
int check(char *p)
{
    while(*p)
    {
        if(*p<48||*p>57)
        return 1;
        p++;
    }
    return 0;
}
int main()
{
    char password[5],*ptr=NULL;
    printf("enter the 4 digit password\n");
    ptr=input(password);
    printf("entered password is %s\n",ptr);
}
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.
...