Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7597063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:04:29+00:00 2026-05-30T22:04:29+00:00

I am working on an assignment for my GUI programming class, in which we

  • 0

I am working on an assignment for my GUI programming class, in which we are to make a windows program that displays the contents of a file in hexadecimal. I have a class that holds the text and creates the hex in string format.

I’m attempting to create an array of character arrays to store each line for output. However, when I use new to create the array of character pointers, I get an access violation error.

I’ve done some searching, but haven’t had any luck finding the answer.

The class has these member variables:

char* fileText;   
char** Lines;
int numChars;  
int numLines;  
bool fileCopied;

My constructor:

Text::Text(char* fileName){  //load and copy file.
   fileText = NULL;
   Lines = NULL;
   fileCopied = ExtractText(fileName);
   if ( fileCopied ) {
      CreateHex();
   }//endif
}//end constructor 

ExtractText loads the file given to the constructor, and copies it into a large string.

bool Text::ExtractText(char fileName[]){
   char buffer = '/0';    //buffer for text transfer
   numChars = 0;              //initialize numLines
   ifstream fin( fileName, ios::in|ios::out );  //load file stream
   if ( !fin ) {     //return false if the file fails to load
      return false;
   }//endif

   while ( !fin.eof() ) {      //count the lines in the file
      fin.get(buffer);
      numChars++;
   }//endwh

   fileText = new char[numLines];  //create an array of strings, one for each line in the file.

   fin.clear();           //clear the eof flag
   fin.seekg(0, ios::beg); //move the get pointer back to the start of the file.

   for ( int i = 0; i < numChars; i++ ) { //copy the text from the file into the string array.
      fin.get(fileText[i]);
   }//endfr
   fileText[numChars-1] = '\0';
   fin.close();
   numLines = (numChars % 16 == 0) ? (numChars/16) : (numChars/16 + 1);
   return true;
}//end fun ExtractText

Then comes the problem code. In the CreateHex function, the first line is where try to create the array of character pointers.

void Text::CreateHex(){
    Lines = new char*[numLines];

As soon as the program runs that line of code, that’s when I get the access violation. I’m not really sure what the problem is, because I’ve used that exact same method before in a previous program. The only difference was the name of pointer. I’m using Borland C++ 5.02 if that makes any difference. It’s not my first choice in compilers, but its what our teacher wants us to use.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:04:30+00:00Added an answer on May 30, 2026 at 10:04 pm

    When you execute the line

    fileText = new char[numLines]
    

    The variable numLines has not yet been initialized. As a member variable, it’s initialized to 0, so you are allocating an empty array for fileText.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an assignment that is telling me to assume that I have
I'm working on a class assignment that started small, so I had it all
I'm working on a homework assignment (a project), for which one criterion is that
I'm working on an assignment for my programming class but I've run into some
So I'm working on a research assignment with a gui and I have 3
I am working on an assignment with polymorphism and have followed online tutorials that
Working on my assignment for Java and I have created a class called Triangle.
I am working on an assignment that uses a base class bankAccount and two
I am working on an assignment that introduces me to operator overloading. I have
We have a GUI of several frames that build their contents dynamically. Each frame

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.