Hi I've been working on a pretty basic program, however I've run into a couple of problems that I've been playing around with for about an hour and I just can't figure it out.
#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[100][4], int * inv, fstream& hardware);
void edit(char string2[100][4], int * inv, fstream& hardware);
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, &inv, hardware);
break;
case 'E':
case 'e':
edit(string2, &inv, hardware);
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, fstream& hardware)
{
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, fstream& hardware)
{
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;
}
}
}
I'm getting the errors:
c:\...\problem2.cpp(64) : error C2100: illegal indirection
c:\...\problem2.cpp(64) : error C2440: '=' : cannot convert from 'char *' to 'char'
There is no context in which this conversion is possible
These errors reference
string2[*inv][c] = token;