ok give me thirty minutes, I will try to fix the indents...
Printable View
ok give me thirty minutes, I will try to fix the indents...
Of course. You need an if before an else. A for loop doesn't cut it.Quote:
parse error before else
alright I tabbed this girl out:
still wont compile or run, what am I missing?Code:/*William Edward McFadden */
/* 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]) && 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;
}
}
}
{
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;
}
}
}
}
}
}
}
Much better indentation. :)
What are your errors now?
Hey It Works!
Thanks guys, I will get some help and get the main working and show you what it looks like, I am guessing that I will need an if statement
like...
[code]
of value =1 then printf"tobad" close program
value = 0, ??nothing?
yes I will put it in c...
Indentation saved the day.
You'll have to change the thread's title now. :)
One last thing. These braces aren't required:
You can delete them, but if you do, preserve the indentation. :)Code:for(R=0; R<6; R++)
{
if (0==strcmp(NAME, name[R]))
{
if (PASSWORD== password[R])
{
return 1;
}
}
}
{
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;
}
}
}
}
}
}
}
it crashes when I delete them?
Uh oh. It shouldn't. The program is no different without them.
Maybe you deleted the wrong ones?
I delete the ones in red.
If it "crashes when you delete them", then your program probably won't work anyway. Put them back in and see what happens.
they work when they are back in
Ugh, you must have deleted the wrong ones.
O well.. I am going to tried to get the if/else statement working in main then I will repost it.
ok new problems...
Here is what I have when I run the program:
Here is what my code looks like:Code:[Session started at 2005-11-12 19:45:55 -0500.]
Please enter your name
darth
Please enter your password
23456
please enter a correct name
Darth
please enter a correct password
23456
Final Project has exited due to signal 10 (SIGBUS).
[Session started at 2005-11-12 19:49:13 -0500.]
Please enter your name
darth
Please enter your password
23456
please enter a correct name
leia
please enter a correct password
12345
Final Project has exited due to signal 10 (SIGBUS).
Code:/*William Edward McFadden */
/* 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);
if (Fpassword == 1);
{
printf("Sorry you really should not be using this program \n");
system ("pause");
exit(0);
}
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 name \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]) && 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;
}
}
}
{
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;
}
}
}
}
}
}
}
/************************************************** **********************************************/
/************************************************** **********************************************/