I formatted your code:
Code:
// Write a programt that inputs (at most 50) records from a sequential file
#include <stdio.h>
#include <stdlib.h>
struct employee // employee structure definition
{
char last_name[15];
char first_name[15];
unsigned month;
unsigned day;
unsigned year;
float annual_salary;
char dept_code;
double phone_number[12];
};
int main(void)
{
FILE *employeePtr; // file pointer to employee document
int result; // used to test whether fread read any bytes
// employee data with default information:
struct employee = {Beast, Savory, 05, 12, 1995, 350000.00, b, 382 - 747 - 6139};
if ((employeePtr=fopen("employee.dat","rb"))==NULL)
{
puts("file could not be opened\n");
}
else
{
// prints statement if the file did open and worked:
printf("file did worked\n");
}
}
Then compiled it:
Code:
test.c: In function ‘main’:
test.c:22:21: error: expected identifier or ‘(’ before ‘=’ token
struct employee = {Beast, Savory, 05, 12, 1995, 350000.00, b, 382 - 747 - 6139};
^
The error that you got was due to a failure to provide a name for the variable. Furthermore, you need to quote your string and character literals:
Code:
struct employee employee_data = {"Beast", "Savory", 05, 12, 1995, 350000.00, 'b', "382-747-6139"};
I am assuming that you will change this:
Code:
double phone_number[12];
To this:
Code:
double phone_number[13];