User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,218 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,208 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 737 | Replies: 1 | Solved
Reply
Join Date: Jan 2008
Posts: 2
Reputation: Rehat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Rehat Rehat is offline Offline
Newbie Poster

Help not sure why program crashes

  #1  
Jan 15th, 2008
hi, I am doing a lab assignment for my C++ class and it wants us to use serveral pointer indirections for each variable. The program runs but then crashs and it seems to occur during the second iteration of a for loop in the arrayGet function. I'm not sure why, something to do with "Access violation reading location".


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

bool vectorGet(vector<string> ****);
bool arrayGet(string ***, vector<string> ****);

int main()
{

vector<string> ****p;
string ***r;
p = new vector<string> ***;
r = new string **;
vectorGet(p);
    

for(int x = 0; x < (*(*(*p)))->size(); x++)
    {
        cout << (*(*(*(*p))))[x] <<endl; 
    }

arrayGet(r, p);

for(int y = 0; y < (*(*(*p)))->size(); y++)
{
    cout << *(*r)[y] <<endl;
}

delete *(*(*p));
delete *(*p);
delete *p;
delete p;

delete *(*r);
delete *r;
delete r;

}

bool vectorGet(vector<string> ****p)
{
*p = new vector<string> **;
*(*p) =    new vector<string> *;
*(*(*p)) = new vector<string>;

string temp;

    fstream document("TopicAin.txt");     
    while(!document.eof() )
    {
    getline(document, temp);
    (*(*(*p)))->push_back(temp);
    }

return true;
}

bool arrayGet(string ***r, vector<string> ****p)
{
*r = new string *;
*(*r) = new string[(*(*(*p)))->size()];


for(int y = 0; y < (*(*(*p)))->size(); y++)
{
    *(*r)[y] = (*(*(*(*p))))[y];    //crash happens here
}

return true;
}

The program reads from a file and fills up the vector then copies the vector to a array and then prints out both variables.

Any help would be great, thanks
Last edited by Narue : Jan 15th, 2008 at 5:05 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 2
Reputation: Rehat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Rehat Rehat is offline Offline
Newbie Poster

Re: not sure why program crashes

  #2  
Jan 15th, 2008
I found my problem. LOL how do I delete this post since no one replied to my problem?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:16 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC