Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void signUp(userType *pUser){
- userType *pCurrent;
- string15 temp;
- int newUser=1;
- char cDump;
- int check, i;
- string8 authorization;
- printf("\n------SIGN UP------\n");
- do{
- newUser=1;
- printf("Enter username (3-15 characters): ");
- scanf("%s%c", temp, &cDump);
- pCurrent=pUser;
- while(pCurrent!=NULL){
- if(strcmp(temp, pCurrent->username)==0)
- newUser=0;
- pCurrent=pCurrent->pNext;
- }
- if(newUser==1)
- strcpy(pUser->username, temp);
- else
- printf("Username already exists.\n");
- } while(strlen(pUser->username)<3 || strlen(pUser->username)>15 || newUser==0);
- do{
- printf("Enter password (6-15 characters, at least one must not be a letter): ");
- scanf("%s", pUser->password);
- for(i=0; i<strlen(pUser->password); i++){
- if(!(pUser->password[i]>='a' && pUser->password[i]<='z'|| pUser->password[i]>='a' && pUser->password[i]<='z'))
- check=1;
- }
- } while(check==0|| strlen(pUser->password)<6 || strlen(pUser->password)>15);
- getUserInfo(&pUser->info);
- do{
- printf("Account type ([S]hopper or [A]dministrator): ");
- scanf("%c%c", &pUser->type, &cDump);
- if(!(pUser->type=='s' || pUser->type=='S' || pUser->type=='a' || pUser->type=='A'))
- printf("Invalid input.\n");
- } while(!(pUser->type=='s' || pUser->type=='S' || pUser->type=='a' || pUser->type=='A'));
- if(pUser->type == 's' || pUser->type == 'S'){
- //shopper account is created
- pUser->creditlimit=5000.00;
- pUser->outstanding=0.00;
- pUser->nItems=0;
- printf("SHOPPER ACCOUNT CREATED.\n\n");
- }
- else if(pUser->type == 'a' || pUser->type == 'A'){
- //administrator account is created
- do{printf("Enter authorization code: ");
- scanf("%s", authorization);
- if(strcmp(authorization,"DLSU2017")==0)
- printf("ADMINISTRATOR ACCOUNT CREATED.\n\n");
- else
- printf("Invalid authorization code.\n");
- }while(strcmp(authorization,"DLSU2017")!=0);
- }
- /*check:
- printf("[USER INFO]\n");
- printf("Username: %s\n", pUser->username);
- printf("Password: %s\n", pUser->password);
- }
- int main(){
- ptrUser pUsers=NULL,
- pNew=NULL,
- pLast=NULL,
- pRun=NULL,
- pTrail=NULL;
- int opt,
- choose,
- accountCount=0;
- char cDump;
- do{
- printf("------[MAIN MENU]------\n");
- printf("1 - Log In\n");
- printf("2 - Sign Up\n");
- printf("3 - Exit\n\n");
- printf("Choose option: ");
- scanf("%d", &choose);
- if(choose==2){
- do{
- pNew=malloc(sizeof(userType));
- pNew->pNext=NULL;
- signUp(pNew);
- if(pUsers==NULL) //list is empty
- pUsers=pNew;
- else if(strcmp(pUsers->username, pNew->username)>0){ //connect at first node
- pNew->pNext=pUsers;
- pUsers=pNew;
- }
- else{ //modifying middle of the list
- pRun=pUsers;
- while(pRun != NULL && strcmp(pRun->username, pNew->username)<0){
- pTrail=pRun;
- pRun=pRun->pNext;
- }
- pTrail->pNext=pNew;
- pNew->pNext=pRun;
- }
- accountCount++;
- printf("Another user? (1 for yes, 0 for no): ");
- scanf("%d%c", &opt, &cDump);
- }while(opt==1);
- }
- if(choose==1)
- logIn(pUsers, accountCount);
- if(choose==3)
- opt=1;
- }while(opt==0);
- displayAll(pUsers);
- freeAll(&pUsers);
- // deleteNode(&pUsers, "cho");
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement