Hey guys, So I have to convert my previous code into a code using pointers and dynamic storage and the problem is, I have no idea how.

I have already read on another forum's examples of Pointers and watched a few tutorials (simple ones) and read from my textbook. Unfortunately, all this is not enough for me to understand. It seems easy when other people do it, but when I look at my problem, I'm completely lost.

So, here is my code I'm supposed to modify :
Note: Sorry, I know some people are stingy about formatting, I don't understand why though, hopefully this is a bit readable..

#include <iostream>
#include <fstream>
using namespace std;

struct Info{
       int ID;
       char fName[32];
       char lName[32];
       double balance;
       int count;
class AccountList{
            void SelectionSort();
            int look();
            int output();
            Info theID[100];
            Info theBalance[100];
            Info firName[100];
            Info laName[100];  
Info in;
ifstream inStream;
ofstream outStream;
int i = 0;

int main(int argc, char* argv[]){
AccountList find;
inStream.open(argv[1]);//opens arg 1 progin.txt
  cout<<"Unable to open input file!"<<endl;}
outStream.open(argv[2]);//opens arg 2 progout.txt
  cout<<"Unable to open output file!"<<endl;}
return 0;                    

int AccountList::look(){
char pID[32], pfName[32], plName[32], pBalance[32];
inStream.getline(pID, 32, ' ');
inStream.getline(pfName, 32, ' ');
inStream.getline(plName, 32, ' ');
inStream.getline(pBalance, 32,'\n');
  int number = atoi(pID);
  double amount = atof(pBalance);
in.ID = atoi(pID);  
strcpy(in.fName, pfName);
strncpy(in.lName, plName, 32);
in.balance = atof(pBalance);  
theID[i].ID = in.ID;
strcpy(firName[i].fName, in.fName);
strcpy(laName[i].lName, in.lName);
theBalance[i].balance = in.balance;

void AccountList::SelectionSort() {
int i, k, indexOfNextSmallest, temp; 
double temp3;
char temp1[32], temp2[32];
for (i = 0; i <= in.count-1 ; i++){
indexOfNextSmallest = i;                   
for (k = i+1; k <= in.count-1; k++)        
if (theID[k].ID < theID[indexOfNextSmallest].ID) 
indexOfNextSmallest = k; 
temp = theID[i].ID;                              
theID[i].ID = theID[indexOfNextSmallest].ID;        
theID[indexOfNextSmallest].ID = temp;
strcpy(temp1, firName[i].fName);
strcpy(firName[i].fName, firName[indexOfNextSmallest].fName);
strcpy(firName[indexOfNextSmallest].fName, temp1);    
temp3 = theBalance[i].balance;
theBalance[i].balance = theBalance[indexOfNextSmallest].balance;
theBalance[indexOfNextSmallest].balance = temp3;

int AccountList::output(){
    for (int i = 0; i < in.count ; i++){
  outStream.setf(ios::fixed | ios::showpoint);
outStream << theID[i].ID <<" "<<firName[i].fName<<" "<<laName[i].lName<<" "<<theBalance[i].balance<<endl;

and an example for the txt file is like :
349334 Smith John 999.00

If anyone would care to explain in lower vocabulary pointers and dynamic storage, I would be very thankful. Or if anyone would care to dumb it down a few notches... that'd be great...

Have a nice day.:$

to convert static array to dynamic

int c[1];
int *c=new int[1];
int *c=(int*)malloc(1*sizeof(int));
//and allways remember to delete all the memory you dynamically allocate
delete [] c;

i hope this was useful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.