I'm a little new to C programming but have some experience. To test my skills, I was trying to build a Bank management program that allows you to create your account, make deposits/withdrawals, etc. The code that I have so far is:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
char username[20];
char password[20];
void create_account(char* usrname, char* passwd) {
printf("==================================CREATE BANK ACCOUNT==================================\n");
while(1) {
printf("Enter a username that is less than 20 characters: ");
scanf("%s", usrname);
if (strlen(usrname) <= 20)
break;
printf("That is not less than 20 characters, try again...\n");
}
while(1) {
printf("Enter a password that is less than 20 characters: ");
scanf("%s", passwd);
if (strlen(passwd) <= 20) {
break;
}
}
printf("Thank you, please sign in now...\n");
sleep(2);
}
int main(void) {
create_account(username, password);
printf("\n%s", username);
printf("\n%s", password);
return 0;
}
I am aware that I have no parameters when I'm calling the function in main but that's because I don't know what parameters to pass through in the function declaration/initialization so for now, I keep it blank. My question is how do I pass 2 arrays into a function, ask the user to create a username and password, store it in their respective arrays and return both arrays to the program? I know it has to do something with pointers but don't know what to do. I know there is a way to do this with structures too but I don't know anything about that, unions, typedefs, or anything advanced. I really am a novice so please, if the answer is simple, don't get mad at me. Thanks in advance!
Edit: I've read through everyone's comments and answers and made the necessary changes to the code except for the one where someone mentioned using fgets instead of scanf. I don't really understand what to do so I just left it, despite the fact that he said scanf is just as dangerous as gets. I think I got everything but if someone has something else, please let me know. Thank you everyone.