I'm not sure what the problem is but strcmp in line 114 returns -10 even if the strings are the same.
Code:
//// main.c
// projectpt1
//
// Created by Justin Howell on 11/17/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
//Preprocessor Directives
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#define buffer_size 512
typedef struct {
char * first[20];
char * last[20];
char * id[20];
char * password[26];
char * admin[4];
}user;
int displayMenu(user * userBase);
int adminLogin(user * userBase);
void adminMenu(user * userBase);
void userLogin(user * userBase);
void userCreate(user * userBase);
int main (int argc, const char * argv[])
{
user userBase[15];
int i = 0;
strcpy(userBase[0].first, "Justin");
strcpy(userBase[0].last, "Howell");
strcpy(userBase[0].id, "ho");
strcpy(userBase[0].password, "ha");
strcpy(userBase[0].admin, "yes");
while (i != 1){
i = (displayMenu(&userBase[0]));
}
return 0;
}
int displayMenu(user * userBase) {
char selection;
char buffer[buffer_size];
int j = 0;
printf("\nWelcome to the SYSTEM\n\n");
printf("---------------------\n");
printf("Please select an option\n");
printf("1. Admin Login\n");
printf("2. User Login\n");
printf("3. User Creation\n");
printf("4. Exit\n\n");
printf("Selection: ");
fgets(buffer, buffer_size, stdin);
selection = atoi(buffer);
switch (selection) {
case 1:
while(j <= 2){
j += (adminLogin(userBase));
}
if (j == 3) {
printf("\nTOO MANY INVALID ATTEMPTS!\n\n");
printf("Press any key to continue");
getchar();
}
selection = NULL;
break;
case 2:
userLogin(userBase);
break;
case 3:
userCreate(userBase);
break;
case 4:
printf("Have a nice day\nEOL");
return 1;
default:
printf("\nINVALID OPTION!\n\n");
return 0;
}
}
int adminLogin(user * userBase){
char buffer[buffer_size];
char userid[20];
char pass[20];
int i = 0;
int j = 0;
printf("********Admin Login********\n");
printf("ID: ");
fgets(buffer, buffer_size, stdin);
strcpy(userid, buffer);
printf("\nPassword: ");
fgets(buffer, buffer_size, stdin);
strcpy(pass, buffer);
printf("%s", userBase->id);
printf("%s", userid);
printf("%d", strcmp((userBase->id), userid));
while (i <= 15) {
if((strcmp(userBase->id, userid)) == 0){
if ((strcmp(*userBase->admin, "yes") == 0)) {
printf("User Authenticated!\n"); return 4;
}else {
printf("You do not have elevated Privilages");
}
}else{
j++;
i++;
*userBase++;
}
}
return 1;
}
void userLogin(user * userBase){
printf("\nOption not yet implemented!\n\n");
printf("Press any key to continue");
getchar();
}
void userCreate(user * userBase){
printf("Option not yet implemented!\n\n");
printf("Press any key to continue");
getchar();
}