October 3, 2008
4.30 am

woot! its 4.30am now , the birds are chirping away and i'm wrecking my brains to find out why i can't seem to crack this last part of my assignment.

here's a glimpse:
/******** #5 Sell and delete car from list ********/
void sell_car(){
CAR *current, *prev;
int found=0;
int key;
char filename[] = "car.txt";
printf("Enter car id to sell: \n");
scanf("%d", &key);
if((fptr = fopen(filename, "a"))==NULL){
printf("Cannot open file\n");
exit(1);
}
else{
if(current==NULL){
printf("List is empty\n");
}
else{
while(!feof(fptr)){
current = (CAR *)malloc(sizeof(CAR));
fscanf(fptr, "%d%s%s%s%d%f\n", &current->id,
current->model,&current->make, current->color,
&current->year, &current->price);

fscanf(fptr,"%d%d%s%s\n", &(current->tech1.cylinders), &current->tech1.tankCapacity,
current->tech1.transmission,current->tech1.driveType);
fscanf(fptr," %s\n", current->extras.extraDetails);

if(key == current->id){
found = 1;
//balance += current->price;

prev->next = current->next;
fprintf(fptr, "%d %s %s %s %d %f\n", current->id, current->model, current->make, current->color,
current->year, current->price);
fflush(stdin);
fprintf(fptr,"%d %d %s %s\n", current->tech1.cylinders, current->tech1.tankCapacity,
current->tech1.transmission,current->tech1.driveType);
fflush(stdin);
fprintf(fptr," %s\n", current->extras.extraDetails);
//printf("Sold. Balance: %.2f\n", balance);
break;
}

}//while
if(found ==0)
printf("No such Car ID\n");
}//else
}//else
}

any help would be greatly appreciated LOL!

0 Comments:

Post a Comment

<< Home