Question: Purpose: 1. Use command line arguments to do the assignment. 2. Use pointers and pointer notation/arithmetic in implementation. 3. Use malloc function to allocate memory.
Purpose:
1. Use command line arguments to do the assignment.
2. Use pointers and pointer notation/arithmetic in implementation.
3. Use malloc function to allocate memory.
Description:
The Prelab 8 is on character and string processing. You have to read an account number and password from a file and store them in two character arrays and display the stored account number and password and then check if the account number and password follow the given specification. The name of the input file name and the length of the account number and password are provided from the command line.
Account Specification: Account number should contain only digits and length should be same as specified by the user from the command line
Implement the following functions for the lab assignment.
int load_data(char* filename, char *acn, char *pwd): This function takes the input file name, two character arrays, integer array . It opens the input file, if unable to open it returns 0 otherwise it loads the account number and password from the text file into the character arrays and returns 1 at the end.
int checkAccountNumber(char * a, int n): This function takes an account number in the form of string and check if the account number consist of n digit number or not if not it returns 0 otherwise it returns 1.
main(): Use command line arguments to read the file name and the length of account number and password from the user. Call load_data function and load the inputs from the file into two characters arrays. Call check account number function and check if the account number is as per the specification and if it doesn't follow the specification throw an error message and ask for new account number from the user. Repeat this until user provide with a valid account number. See sample output below to display the error messages and collect information the user.
Note
Use of arrays is not allowed for the prelab instead start with a (character) pointer and use malloc function to allocate only the required amount of memory.
Use POINTER NOTATION AND POINTER ARITHMETIC only to implement the prelab assignment.
You are allowed to use functions from ctype.h and string.h library.
Sample output
Characters in bold are inputs from the user.
./a.out
Insufficient arguments
./a.out input.txt 6
Account number is 1112356
Password number is Dft10
Invalid account number account should be 6 digit number
Enter the account number again: 1122er
Invalid account number account should be 6 digit number
Enter the account number again: er1122
Invalid account number account should be 6 digit number
Enter the account number again: 112233
Your account number is 112233
input.txt
1357924680 Gui11iam$
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
