Hey everyone I did a tutorial on a website that seems to combines C and C++ for the program witch is an inventory program.
Here it is. It runs and compiles fine but after I enter the data at the end it crashes on me. I am still new to C\C++ so any help is verry apreciated.
Code:
// Program to perform file processing using the FILE structure
// Author: Jules Larson. Revised by Jeremy Jones 2005
#include <iostream>
using namespace std;
int main()
{
char Make[20], Model[20];
unsigned int CarYear;
long Mileage;
FILE *CarInventory = fopen("cars.inv", "w");
cout << "Enter the following pieces of information\n";
cout << "Make: "; gets(Make);
cout << "Model: "; gets(Model);
cout << "Year: "; cin >> CarYear;
cout << "Mileage: "; cin >> Mileage;
fprintf(CarInventory, "%s\n", Make);
fprintf(CarInventory, "%s\n", Model);
fprintf(CarInventory, "%s\n", CarYear);
fprintf(CarInventory, "%s\n", Mileage);
FILE *Carinventory = fopen("cars.inv", "r+");
fscanf(CarInventory, "%s\n", Make);
fscanf(CarInventory, "%s\n", Model);
fscanf(CarInventory, "%d\n", &CarYear);
fscanf(CarInventory, "%d\n", &Mileage);
cout << "Information about the car";
cout << "\nMake: " << Make;
cout << "\nModel: " << Model;
cout << "\nYear: " << CarYear;
cout << "\nMIleage: " << Mileage;
fclose(CarInventory);
cout << endl;
return 0;
}
Thanks