1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
/*
Peter Moodie - Parking Space Allocation Software
*/
/*
Preproccessor Directives( Header Files )
*/
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib>
#include <time.h>
#include <ctype.h>
#include <direct.h>
FILE *cfPtr;
FILE *file;
typedef struct robot ROBOT;
struct robot {
char *rname;
char *pass;
};
ROBOT robots[3];
struct database{
char Fname;
char lname;
int work_hours;
int acctNum;
};
struct database employees;
void create(void)//CODE TO WRITE TO RANDOM ACCESS FILE
{
file = fopen("C:/NixGen PSAS/credit.dat", "r+"); /* create a file for reading and writing */
if(file==NULL) {
printf("An error has occurred.\n");
}
else{
printf ("Enter account Number (1 to 100, 0 to end input)\n ");
scanf("%d", &employees.acctNum);
while (employees.acctNum != 0) {
printf("Enter Last Name, First Name, Expected Work Hours\n ");
scanf ( "%s%s%f", &employees.lname, &employees.Fname, &employees.work_hours);
fseek(file, (employees.acctNum - 1) * sizeof(struct database), SEEK_SET);
fwrite(&employees, sizeof(struct database), 1, file);
printf("Enter account number\n ");
scanf("%d", &employees.acctNum);
}
}
fclose(file);
getch();
}
//THE ERROR LIES HERE
void viewemp(void)
{
file = fopen("C:/NixGen PSAS/credit.dat", "r");
if(file==NULL) {
printf("Error: can't open file.\n");
}
else {
printf("%6s%16s%11s%15s\n", "Acct", "Last Name", "First Name", "Balance");
while (!feof(file)) {
fread(&employees, sizeof(struct database), 1, file);
if (employees.acctNum != 0)
printf("%d", employees.acctNum);//IT PRINTS THE INTEGER
printf("%s", employees.lname); //THREAD ERROR WHEN IT COMES TO THE STRING
}
}
fclose(file);
getch();
clrscr();
login();
}
|