EMPLOYEEレコードファイルを作成するためにクラスで行っているこのプログラム。2 つの構造体を作成しました。1 つは従業員と呼ばれ、もう 1 つは日付と呼ばれます。EMPLOYEE 構造体には、1 つの char 配列、1 つの int、6 つの float 値、および DATE (別の構造体) があります。DATE 構造体には 3 つの int 値 (月、日、年) しかありません。
person[1000] という EMPLOYEE 型の配列を作成しました。
これが私のコードです。ビジュアル スタジオで fwrite.c Expression: (Stream !=NULL) を指す debug assertion failed エラーが発生し続けます。構造体を保存しようとしたことがないので、freadまたはfwiteに関係していると確信しています。
この関数の最初のポイントは、ファイルが存在し、空でない場合に配列を設定することです。そのため、ユーザーが配列へのデータの格納を開始すると、添え字が更新されます。ここにはおそらく他にもいくつかの問題があることはわかっていますが、まず最初に、読み書きの部分です。
再度、感謝します、
マイク
void loadPayRoll(EMPLOYEE person[], int *i)
{
char sValidate[5] = "exit";
FILE *f;
int count = 0;
f = fopen("emplyeeRecords.bin", "rb");
if(f){
while(fread(&person[*i], sizeof(person), 1, f) > 0){
(*i)++;
}
fclose(f);
}
else {
while (strcmp( sValidate, person[*i].name)) {
fopen("employeeRecords.bin", "ab+");
printf("Please enter name or type exit to return to main menu: ");
scanf("%s", person[*i].name); //must use the '->' when passing by by refrence, must use '&' sign
flush;
if (!strcmp( sValidate, person[*i].name))
break;
printf("\nPlease enter age of %s: ", person[*i].name);
scanf("%i", &person[*i].age);
flush;
printf("\nPlease enter the hourlyWage for %s: ", person[*i].name);
scanf("%f", &person[*i].hourlyWage);
flush;
printf("\nPlease enter the hours worked for %s: ", person[*i].name);
scanf("%f", &person[*i].hoursWkd);
if (person[*i].hoursWkd > 40) {
person[*i].regPay = person[*i].hoursWkd * 40;
person[*i].otHoursWkd = person[*i].hoursWkd - 40;
person[*i].otPay = person[*i].otHoursWkd * (person[*i].hourlyWage * 1.5);
person[*i].totalPay = person[*i].regPay + person[*i].otPay;
}
else {
person[*i].totalPay = person[*i].hoursWkd * person[*i].hourlyWage;
}
flush;
printf("\nEnter 2 digit month: ");
scanf("%i", &person[*i].payDate.month); //must use the '->' when passing by by refrence, must use '&' sign
flush;
printf("\nEnter 2 digit day: ");
scanf("%i", &person[*i].payDate.day); //must use the '->' when passing by by refrence, must use '&' sign
flush;
printf("\nEnter 4 digit year: ");
scanf("%i", &person[*i].payDate.year); //must use the '->' when passing by by refrence, must use '&' sign
flush;
fwrite(&person[*i], sizeof(person), 1, f);
fclose(f);
(*i)++;
}
}
}//end function loadPayRoll