In a linked list of integers using pointers to structures instead of array indices. The integers must be read from an input file determined by prompting the user. Allocate an array of 50 C++ structures defined as follows:
struct entry {
int value; // the integer read in
struct entry *nextPtr; // pointer to the next structure
};
You must also declare a struct entry *firstPtr which points to the first entry in the linked list. You must declare a struct *lastPtr which points to the last entry in the linked list. You must NOT allow the lastPtr to point beyond the end of the array.
After reading in the integers in the file print out (using pointers, not array indices) the integers read in the order they were read with no more than 10 entries per line.
This is the code i've came up with so far:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct entry *getEntry() {
static int nextEntry = 0; static struct entry array[50];
if (nextEntry >= 50) return NULL;
array[nextEntry].value = 0;
nextEntry++; return &array[nextEntry - 1];
}
int main()
{
int value;
ifstream inFile;
string input; // holds string for filename
cout << "Enter file name: "; //opens the file user enters
cin >> input;
inFile.open(input);
while (inFile.good())
{
inFile >> value[array];
}
inFile.close();
ofstream outFile("outFile.txt");//opens output txt
}
If someone could help explain an easier way or fix the issues with my cod

New Topic/Question
Reply


MultiQuote



|