D
didier2309
I get segemntation fault when I enter that function it executes till
wcpcpy(lacc_num, L"000-00-0001");
Here is the function:
It executes till the statement wcpcpy(laccnum, L"000-00-0001");
int acopen:pen_acc()
{
int accnum;
char stname[80];
FILE *getaccnum;
getaccnum = fopen("numbers", "r");
if(getaccnum == NULL){
cout << "No account has been openned yet\n";
wcpcpy(lacc_num, L"000-00-0001");
}
else{
fseek(getaccnum, 11, SEEK_END);
fscanf(getaccnum, "%S", lacc_num);
int sec[9], accnum;
sec[0] = wctob(lacc_num[0]);
sec[1] = wctob(lacc_num[1]);
sec[2] = wctob(lacc_num[2]);
sec[3] = wctob(lacc_num[4]);
sec[4] = wctob(lacc_num[5]);
sec[5] = wctob(lacc_num[7]);
sec[6] = wctob(lacc_num[8]);
sec[7] = wctob(lacc_num[9]);
sec[8] = wctob(lacc_num[10]);
for(int i = 0; i < 9; i--){
accnum = accnum*10 +sec ;
}
int tempaccnum;
accnum = accnum++;
tempaccnum = accnum;
for(int i = 8; i >= 0; i--){
sec = tempaccnum - (tempaccnum/10)*10;
tempaccnum = tempaccnum/10;
}
lacc_num[0] = btowc(sec[0]);
lacc_num[1] = btowc(sec[1]);
lacc_num[2] = btowc(sec[2]);
lacc_num[3] = '-';
lacc_num[4] = btowc(sec[3]);
lacc_num[5] = btowc(sec[4]);
lacc_num[6] = '-';
lacc_num[7] = btowc(sec[5]);
lacc_num[8] = btowc(sec[6]);
lacc_num[9] = btowc(sec[7]);
lacc_num[10] = btowc(sec[8]);
lacc_num[11] = '\0';
}
fclose(getaccnum);
FILE *putn;
putn = fopen("numbers","ab");
if(putn == NULL){
cout << "\ncannnot open file\n";
return 1;
}
FILE *out;
out = fopen("account","ab");
if(out == NULL) {
cout << "\ncannot open file";
return 1;
}
cout <<"\nthe account number is: ";
printf("%S\n",lacc_num);
cout << "enter name: \n";
cin >> sname;
cout << "enter last name\n";
cin >> slastname;
cout << "birthday? Day, month and year seperately (in
numbers)...\n";
do{
cin >> sbirth_day ;
if(!getint(sbirth_day))
badent();//call badebt()
}while(!getint(sbirth_day));
do{
cin >> sbirth_month ;
if(!getint(sbirth_month))
badent();
}while(!getint(sbirth_month));
do{
cin >> sbirth_year;
if(!getint(sbirth_year))
badent();
}while(!getint(sbirth_year));
cout << "street address?(house number and street name only:
Enter [space]~ to end address) \n";
cin >> shousenum ;
do{
cin >> stname;
strcat(sstreetname, stname);
strcat(sstreetname, " ");
}while(strcmp(stname,"~"));
cout << "city?\n";
cin >>scity;
do{
cout <<"zipcode?\n";
cin >> szip;
}while(!getlong(szip));
cout << "phone and area code?\n";
do{
cin >> sphone;
if(!getlong(sphone))
badent();
}while(!getlong(sphone));
do{
cin >> sarea ;
if(!getint(sarea))
badent();
}while(!getint(sarea));
do{
cout << "social security?\n";
cin >>ssocial;
}while(!getlong(ssocial));
do{
cout << "deposit amount?\n";
cin >>sbalance;
}while(!(getfloat(sbalance)));
fprintf(out, "%S\n", lacc_num);
fprintf(putn, "%S\n", lacc_num);
fprintf(out ,"%s\n", sname);
fprintf(out ,"%s\n", slastname);
fprintf(out, "%s\n", sbirth_day);
fprintf(out, "%s\n", sbirth_month);
fprintf(out, "%s\n", sbirth_year);
fprintf(out, "%s\n", sstreetname);
fprintf(out, "%s\n", shousenum);
fprintf(out, "%s\n", scity);
fprintf(out, "%s\n", szip);
fprintf(out, "%s\n", sphone);
fprintf(out, "%s\n", sarea);
fprintf(out, "%s\n", ssocial);
fprintf(out, "%s\n", sbalance);
fclose(putn);
fclose(out);
return 0;
}
-
wcpcpy(lacc_num, L"000-00-0001");
Here is the function:
It executes till the statement wcpcpy(laccnum, L"000-00-0001");
int acopen:pen_acc()
{
int accnum;
char stname[80];
FILE *getaccnum;
getaccnum = fopen("numbers", "r");
if(getaccnum == NULL){
cout << "No account has been openned yet\n";
wcpcpy(lacc_num, L"000-00-0001");
}
else{
fseek(getaccnum, 11, SEEK_END);
fscanf(getaccnum, "%S", lacc_num);
int sec[9], accnum;
sec[0] = wctob(lacc_num[0]);
sec[1] = wctob(lacc_num[1]);
sec[2] = wctob(lacc_num[2]);
sec[3] = wctob(lacc_num[4]);
sec[4] = wctob(lacc_num[5]);
sec[5] = wctob(lacc_num[7]);
sec[6] = wctob(lacc_num[8]);
sec[7] = wctob(lacc_num[9]);
sec[8] = wctob(lacc_num[10]);
for(int i = 0; i < 9; i--){
accnum = accnum*10 +sec ;
}
int tempaccnum;
accnum = accnum++;
tempaccnum = accnum;
for(int i = 8; i >= 0; i--){
sec = tempaccnum - (tempaccnum/10)*10;
tempaccnum = tempaccnum/10;
}
lacc_num[0] = btowc(sec[0]);
lacc_num[1] = btowc(sec[1]);
lacc_num[2] = btowc(sec[2]);
lacc_num[3] = '-';
lacc_num[4] = btowc(sec[3]);
lacc_num[5] = btowc(sec[4]);
lacc_num[6] = '-';
lacc_num[7] = btowc(sec[5]);
lacc_num[8] = btowc(sec[6]);
lacc_num[9] = btowc(sec[7]);
lacc_num[10] = btowc(sec[8]);
lacc_num[11] = '\0';
}
fclose(getaccnum);
FILE *putn;
putn = fopen("numbers","ab");
if(putn == NULL){
cout << "\ncannnot open file\n";
return 1;
}
FILE *out;
out = fopen("account","ab");
if(out == NULL) {
cout << "\ncannot open file";
return 1;
}
cout <<"\nthe account number is: ";
printf("%S\n",lacc_num);
cout << "enter name: \n";
cin >> sname;
cout << "enter last name\n";
cin >> slastname;
cout << "birthday? Day, month and year seperately (in
numbers)...\n";
do{
cin >> sbirth_day ;
if(!getint(sbirth_day))
badent();//call badebt()
}while(!getint(sbirth_day));
do{
cin >> sbirth_month ;
if(!getint(sbirth_month))
badent();
}while(!getint(sbirth_month));
do{
cin >> sbirth_year;
if(!getint(sbirth_year))
badent();
}while(!getint(sbirth_year));
cout << "street address?(house number and street name only:
Enter [space]~ to end address) \n";
cin >> shousenum ;
do{
cin >> stname;
strcat(sstreetname, stname);
strcat(sstreetname, " ");
}while(strcmp(stname,"~"));
cout << "city?\n";
cin >>scity;
do{
cout <<"zipcode?\n";
cin >> szip;
}while(!getlong(szip));
cout << "phone and area code?\n";
do{
cin >> sphone;
if(!getlong(sphone))
badent();
}while(!getlong(sphone));
do{
cin >> sarea ;
if(!getint(sarea))
badent();
}while(!getint(sarea));
do{
cout << "social security?\n";
cin >>ssocial;
}while(!getlong(ssocial));
do{
cout << "deposit amount?\n";
cin >>sbalance;
}while(!(getfloat(sbalance)));
fprintf(out, "%S\n", lacc_num);
fprintf(putn, "%S\n", lacc_num);
fprintf(out ,"%s\n", sname);
fprintf(out ,"%s\n", slastname);
fprintf(out, "%s\n", sbirth_day);
fprintf(out, "%s\n", sbirth_month);
fprintf(out, "%s\n", sbirth_year);
fprintf(out, "%s\n", sstreetname);
fprintf(out, "%s\n", shousenum);
fprintf(out, "%s\n", scity);
fprintf(out, "%s\n", szip);
fprintf(out, "%s\n", sphone);
fprintf(out, "%s\n", sarea);
fprintf(out, "%s\n", ssocial);
fprintf(out, "%s\n", sbalance);
fclose(putn);
fclose(out);
return 0;
}
-