I've been working on a project for a few days now, and I am running out of time by trying to research everything I am doing. My task for this particular program is to create an inventory program that reads from a file and then allows the user to manipulate the data and overwrite the file.
I am getting the following error and I don't know how to correct it:
c:\documents and settings\jayson\my documents\visual studio 2008\projects
\solution 3\assignment 3\hardware.cpp(113) : error C2065: 'hardware' : undeclared identifierc:\documents and settings\jayson\my documents\visual studio 2008\projects
\solution 3\assignment 3\hardware.cpp(113) : error C2228: left of '.seekg' must have class/struct/union
type is ''unknown-type''
Here's the code:
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string.h>
using namespace std;
const int MAX = 100;
const int MAXINV = 100;
const int ROWS = 4;
void view(char *string2, int * inv);
void edit(char *string2, int * inv);
void main()
{
fstream hardware;
int *inv = 0;
int c = 0;
char input;
char string1[MAX];
char *string2[100][4];
char *delim = ";";
char *token;
hardware.open("hardware.dat", ios::in | ios::out);
if (hardware.fail())
{
cout << "File Open Failed.\n";
exit(1);
}
cout << "Menu\n" << endl
<< "Action: Enter: " << endl
<< "View Inventory V" << endl
<< "Edit Entry E" << endl
<< "Quit Q" << endl;
cin >> input;
switch(input)
{
case 'V':
case 'v':
view(string2[100][4], (int*) *inv);
break;
case 'E':
case 'e':
edit(string2[100][4], (int*) inv);
break;
default:
exit(1);
}
while (! hardware.eof())
{
cin.getline(string1, MAX);
token = strtok(string1, delim);
while (token != NULL)
{
cout << "token " << c << " is " << endl << token << endl;
if (c >= ROWS)
{
c=0;
inv++;
}
string2[*inv][c] = token;
token = strtok(NULL,delim);
c++;
}
}
hardware.close();
}
void view(char *string2[100][4], int * inv)
{
int i,j;
for (i=0; i <= *inv; i++)
{
for (j=0; j <= 4; j++)
{
cout << string2[i][j] << endl;
}
}
}
void edit(char *string2[100][4], int * inv)
{
int num;
int i,j;
char string1[MAX];
cout << "Enter Inv. Number: ";
cin >> num;
for (j=0; j <= 4; j++)
{
cout << string2[num][j] << ";" << endl;
}
cin.getline(string1, MAX);
hardware.seekg(0,ios::beg);
for (i=0; i <= *inv; i++)
{
for (j=0; j <= 4; j++)
{
cout << string2[i][j] << ";" << endl;
}
}
}
Is there a better way to do this? I've read half the C++ book over the past few days and my head is spinning :confused: