Hi! I have an assignment and need to do database using C. I tried starting it and this is what I came up with so far. I'm still a beginner but I tried indenting it as well as I could (sorry if it's not good enough!). Now my problem is that an error came up and it won't give me the line where the error is (I'm suspecting 50errors or so will come up after this one is solved). Can someone please find me some things which I'm doing wrong and explain to me the exact use of fseek, because even though I'm using it, I still can't fully get what it's used for. Below is my source code, many thanks!
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ddd.h"
int menu()
{
int choice = 0;
do
{
printf("Welcome to the F1 database, please choose one of the following options:\n");
printf("\t Press 1 to update the driver's details.\n");
printf("\t Press 2 to enter the race results.\n");
printf("\t Press 3 to see the driver's current standings.\n");
printf("\t Press 4 to exit the program.\n");
scanf("%d", &choice);
}
while ((choice < 1) && (choice > 4));
{
printf("\a This is an invalid option, please try again.\n");
}
return choice;
}
int main()
{
int choice = 0;
int recordNum = 0;
Driver driver = {0};
do
{
choice = menu();
switch (choice)
{
case 1://Updating the driver's details
updatecurrentrecord(&driver);
addRecord(FILENAME, &driver);
break;
case 2://Entering the race results
//enterresults;
break;
case 3://Displaying the driver standings
printDriverstandings(listHead);
break;
default:
break;
}
}
while (choice != 4);
}
//Case 1
int updatecurrentrecord(const char *filename, int recordNum, Driver *driver)
{
int ret = 0;
int carnumber = 0;
FILE *file = fopen(filename, "r+b");
system("cls");
printf("Please enter the car number which you would like to add or update : ");
scanf("%d",driver->carnumber);
while ((carnumber < 1) || (carnumber > 26))
{
printf("Enter a valid car number between 1 and 26, please try again. \a \n");
scanf("%d",driver->carnumber);
}
fclose(file);
return ret;
}
void enterdriverdetails(Driver *driver);
{
if (fseek(file, sizeof(Driver) * carnumber, SEEK_SET) != 0)
{
FILE *file = fopen(filename, "w+b");
system("cls");
printf("The car number chosen has no details ");
printf("Please enter the driver's full name: ");
scanf("%s", driver->drivername);
printf("Please enter the car's constructor team name: ");
scanf("%s", driver->teamname);
printf("Please enter the number of points earned so far in the Formula 1 season: ");
scanf("%d", &driver->points);
}
}
int updatecurrentrecord(const char *filename, int recordNum, Driver *driver)
{
fopen(file);
if (fseek(file, sizeof(Driver) * recordNum, SEEK_SET) == 0)
{
system("cls");
printf("The car number chosen akready has a driver! Please choose one of the following options: \n");
printf("\t Press 0 to change the driver's name. \n");
printf("\t Press 1 to change the car's constructor team name. \n");
scanf("%d", &correctionchoice);
}
while ((correctionchoice < 0) || (correctionchoice > 1))
{
printf("Please enter a valid choice, please try again. \a \n");
}
if (correctionchoice == 0)
{
printf("Please enter the driver's new full name: ");
scanf("%s", driver->drivername);
}
else
{
printf("Please enter the car's new constructor team name: ");
scanf("%s", driver->teamname);
}
fclose(file);
return ret;
}
.