-
signal 10 (SIGBUS)
ok new problems...
Here is what I have when I run the program:
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).
Here is what my code looks like:
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;
}
}
}
}
}
}
}
/************************************************** **********************************************/
/************************************************** **********************************************/
-
Sorry, I forgot the question..
what is sigbus code 10??
-
You've really got a lot of issues with this code. For instance:
Code:
if (Fpassword == 1);
Fpassword is declared as a FILE type. Fpassword normally either returns a pointer to the open file or a null pointer value if a file open error occurred. Also, a semicolon should not be after an if statement. It negates the condition test.
I would suggest that you pass the file name to the password function. Then open the file in the password function, do the processing, close the file and return a value dependent upon the successs or failure of the processing.
-
Aside from all the standard non-compliance in your code, there are a couple spots that can generate errors. First you never check the result from fopen() calls before you start using the file handles. Next, if any of your fscanf() calls fail to input a string into the string buffer, your strcmp() calls will overrun the buffer. My best guess is your program is failing on the strcmp() calls. Try printing out the strings before you compare them, and see what happens.
-
OK I took your advice, now the program continues to ask again and again if you did not give give the correct answer. ALSO I can only use leia and password 12345, I can not use any of the other names and passwords from the text file password.txt:
Code:
leia 12345
darth 23456
r2d2 34567
solo 45678
jabba 56789
yoda 67890
Here is the program (all edited and such)
Code:
/* Location of all files is at: */
/* /users/williammcfadden/Documents/school/EGR 115/Final Project/ */
#include <stdio.h>
#include <stdlib.h>
#include <string.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 == 0)
{
printf("Sorry you really should not be using this program \n");
system ("pause");
exit(0);
}
printf("\n\n\n\n");
printf("hello ya'll \n");
fclose(Fpassword);
fclose(Fplanes);
fclose(Fdistout);
exit(0);
}
/************************************************** **********************************************/
/************************************************** **********************************************/
/************************************************** **********************************************/
/************************************************** **********************************************/
/************************************************** **********************************************/
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]) && 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 \n");
scanf("%i", &PASSWORD);
for(z=0; z<6; z++)
{
if(0==strcmp(NAME, name[z]) && PASSWORD == password[z])
{
return 0;
}
}
}
}
}
/************************************************** **********************************************/
/************************************************** **********************************************/
-
To avoid duplicating my post twice, please see my last post.
The errors in that post, mainly the two scanf() errors (cause of your crash) and the FILE * == int comparision error still exist. (As well as the memory leaking.) And do try not to double-thread stuff, it really does not speed up help.