Thanks in advance.
P.S. Sorry about the double post. Our connection's slow so I refreshed the page and the other post was created. Sorry
This post has been edited by preeengles: 20 April 2009 - 05:31 AM




Posted 20 April 2009 - 05:22 AM
This post has been edited by preeengles: 20 April 2009 - 05:31 AM
Posted 20 April 2009 - 06:08 AM
Posted 20 April 2009 - 06:33 AM
preeengles, on 20 Apr, 2009 - 05:08 AM, said:
Posted 20 April 2009 - 10:56 PM
janotte, on 20 Apr, 2009 - 05:33 AM, said:
void disp_all()
{
record stud;
int i, rec_num = 0;
FILE *fp1;
/************************************************************/
//this part here has something to do with counting the number of records in the file
rewind(fp);
clrscr();
if((fp1=fopen("new.dat","wb")) == NULL)
{
printf("\n\nUnable to Open new.dat File - exiting\n\n");
exit(1);
}
while(fread(&stud, sizeof(stud), 1, fp))
{
if(stud.snum > 0)
{
fwrite(&stud, sizeof(stud), 1, fp1);
rec_num++;
}
}
fclose(fp);
fclose(fp1);
if((remove("std.dat")) != 0)
{
printf("\n\nError! Obsolete file: std.dat, was not deleted - exiting\n\n");
exit(1);
}
else
{
rename("new.dat", "std.dat");
if((fp=fopen("std.dat","rb+")) == NULL)
{
if((fp = fopen("std.dat", "wb+")) == NULL)
{
printf("\n\nUnable to Open std.dat File - exiting\n\n");
getch();
exit(1);
}
}
}
/************************************************************/
//this part displays the records
rewind(fp);
printf("STUDENT#\t%-16s%-16s%-12s%-12s%-12s\n\n","LAST NAME","FIRST NAME","MI","BDAY", "COURSE ");
while(fread(&stud,sizeof(stud),1,fp))
{
if(stud.snum > 0)
{
printf("%lld\t", stud.snum); //student number
printf("%-16s", stud.lname);
printf("%-16s", stud.fname);
printf("%-12s", stud.mi);
printf("%-12s", stud.bday);
printf("%-12s\n", stud.course);
}
}
printf("\n\nThere are currently %d student records\n\n", rec_num);
printf("\n\nPress any key to go back to menu.");
getch();
}
Posted 21 April 2009 - 06:40 AM
Posted 21 April 2009 - 08:15 AM
janotte, on 21 Apr, 2009 - 07:40 AM, said:
void displayRecords(record studList[], int size) {
int i;
printf("STUDENT#\t%-16s%-16s%-12s%-12s%-12s\n\n","LAST NAME","FIRST NAME","MI","BDAY", "COURSE ");
for (i=0; i<size; i++) {
printf("%lld\t", studList[i].snum);
printf("%-16s", studList[i].lname);
printf("%-16s", studList[i].fname);
printf("%-12s", studList[i].mi);
printf("%-12s", studList[i].bday);
printf("%-12s\n", studList[i].course);
}
printf("\n\nThere are currently %d student records\n\n", size);
printf("\n\nPress any key to go back to menu.");
}
int loadRecords(char *fileName, record studList[]) {
record stud;
int readCount;
FILE *fp;
if((fp=fopen(fileName,"rb")) == NULL) { return 0; }
readCount = 0;
while(fread(&stud,sizeof(stud),1,fp)) {
if(stud.snum > 0) { studList[readCount++] = stud; }
}
return readCount;
}
void sortRecords(record studList[], int size) { /* your code here */ }
This post has been edited by baavgai: 21 April 2009 - 08:16 AM
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
