I am currently working on a final program for school, the first part of my program calls a function that calls a file (password.txt). which looks like:
leia 12345
darth 23456
r2d2 34567
solo 45678
jabba 56789
yoda 67890
with the first column being the user name and the second being the password. My function ask the user to enter his/her username then password... all is well accept it does not work. I am using apples xcode to build this. here is my program so far: PLEASE note I have nothing in main yet, after I get the function working I have to make the program close if the user inputs the password wrong three times.
ADDED!!!! Ok I just realized I will make this function send back 1 or 0, if it sends back 0 I will have main close the program, if it sends back 1 it will let the main part of the program continue (in this case print something but a lot more goes there, this is just the first part).
Code:
/* Location of all files is at: */
/* /users/williammcfadden/Documents/school/EGR 115/Final Project/ */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* function Declarations */
int password(FILE *);
main()
{
FILE *Fpassword;
FILE *Fplanes;
FILE *Fdistout;
Fpassword=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/password.txt", "r");
Fplanes=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/planes.txt", "w");
Fdistout=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/distlog.out", "w");
/*password function */
password(Fpassword);
printf("hello ya'll \n");
fclose(Fpassword);
fclose(Fplanes);
fclose(Fdistout);
}
/************************************************************************************************/
/************************************************************************************************/
/************************************************************************************************/
int password(FILE *Fpassword)
{
char NAME[50];
int PASSWORD;
int l;
char* name[6];
for(l=0; l<6; l++)
{
name[l]= malloc (50);
}
int password[6];
int i;
int h;
int R;
int z;
for(i=0; i<6; i++)
{
fscanf(Fpassword, "%s", name[i]);
fscanf(Fpassword, "%d", password[i]);
}
printf("Please enter your\n");
scanf("%s", NAME);
printf("Please enter your password \n");
scanf("%i", &PASSWORD);
for(h=0; h<6; h++)
{
if (0==strcmp(NAME, name[h]))
{
if (PASSWORD == password[h])
{
return 1;
}
else {
printf("please enter a correct name \n");
scanf("%s", NAME);
printf("please enter a correct password \n");
scanf("%i", PASSWORD);
for(R=0; R<6; R++)
{
if (0==strcmp(NAME, name[R]))
{
if (PASSWORD== password[R])
{
return 1;
}
}
}
else printf("ONE LAST TIME BUDDY \n");
{
printf("please enter your name \n");
scanf("%s", NAME);
printf("please enter your password");
scanf("%i", PASSWORD);
for(z=0; z<6; z++)
{
if( 0==strcmp(NAME, name[z]))
{
if (PASSWORD == password[z])
{
return 0;
}
}
Currently this program will not compile or run, earlier (before I broke it) it would compile and give me a sigbus10 or 11 error.
IF you want to know what the instructor wants the password function to do. Here is what he said:
This program must be secure. The user must input their name and pin number, if both (name and pin) matches the list you have in a text file on the disk (password.txt), than the user gets access to this program. The program should allow 3 tries for name and password entry, if unsuccessful after 3 tries the program should print a message to the user and terminate.
More requirements, In addition to our standards:
The password.txt file will only contain the six names and pin numbers mentioned above.
Your program should be able to process the maximum of 50 aircrafts.
You must use a two dimensional array for the aircraft position data.
The main function must do very little other than calling other functions and passing parameters to those functions.
Your program should be modularly designed with functions designed to do one task and one task well.
Functions that calculate should not print. And functions that print should do minimal calculations if any.
Put functions below the main and place prototypes above the main.
Do not use global variables. Pass data back and forth via parameters or as return values.
Make your functions as general as possible so that they can be called more than once if needed.
Document your main function as well as every function you write.
Use defined constants for ALL constants in your program. """"
THANKS