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 3318568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:43:16+00:00 2026-05-17T22:43:16+00:00

I’m working on an email validation program for my cmpsci class and am having

  • 0

I’m working on an email validation program for my cmpsci class and am having trouble with this one part.

What I’m doing is reading a list of valid top level domains from a text file into a vector class I wrote myself (I have to use a custom vector class unfortunately). The problem is that the program reads in and adds the first few domains to the vector all well and fine, but then crashes when it gets to the “org” line. I’m completely stumped why it works for the first few and then crashes.
Also, I have to use a custom string class; that’s why I have the weird getline function (so I get the input in a char* for my String constructor). I’ve tried using the standard string class with this function and it still crashed in the same way so I can rule out the source of the problem being my string class. The whole program is quite large so I am only posting the most relevant parts. Let me know if more code is needed please. Any help would be awesome since I have no clue where to go from here. Thanks!

The ReadTlds function:

void Tld::ReadTlds() {
    // Load the TLD's into the vector
    validTlds = Vector<String>(0); // Init vector; declaration from header file: "static Vector<String>validTlds;"
    ifstream in(TLD_FILE);
    while(!in.eof()) {
        char tmpInput[MAX_TLD_LENGTH];   // MAX_TLD_LENGTH equals 30
        in.getline(tmpInput, MAX_TLD_LENGTH);
        validTlds.Add(String(tmpInput)); // Crashes here!
    }
}

My custom vector class:

#pragma once

#include <sstream>

#define INIT_CAPACITY 100
#define CAPACITY_BOOST 100

template<typename T> class Vector {
public:
 // Default constructor
  Vector() {
   Data=NULL;
   size=0;
   capacity=INIT_CAPACITY;
  }
 // Init constructor
 Vector(int Capacity) : size(0), capacity(Capacity) {
  Data = new T[capacity];
 }

 // Destructor
 ~Vector() {
  size=0;
  Data = NULL;
  delete[] Data;
 }

 // Accessors
 int GetSize() const {return size;}

 T* GetData() {return Data;}

 void SetSize(const int size) {this->size = size;}


  // Functions
  void Add(const T& newElement) {
   Insert(newElement, size);
  }

  void Insert(const T& newElement, int index) {
  // Check if index is in bounds
  if((index<0) || (index>capacity)) {
   std::stringstream err;
   err << "Vector::Insert(): Index " << index << " out of bounds (0-" << capacity-1 << ")";
   throw err.str();
  }

   // Check capacity
   if(size>=capacity)
   Grow();

   // Move all elements right of index to the right
   for(int i=size-1; i>=index; i--)
   Data[i+1]=Data[i];

    // Put the new element at the specified index
   Data[index] = newElement;
   size++;
  }

  void Remove(int index) {
   // Check if index is in bounds
  if((index<0) || (index>capacity-1)) {
   std::stringstream err;
   err << "Vector::Remove():Index " << index << " out of bounds (0-" << capacity-1 << ")";
   throw err.str();
  }

  // Move all elements right of index to the left
   for(int i=index+1; i<size; i++)
    Data[i-1]=Data[i];
  }

 // Index operator
 T& operator [] (int index) const {
  // Check if index is in bounds
  if((index<0) || (index>capacity-1)) {
   std::stringstream err;
   err << "Vector operator[]:Index " << index << " out of bounds (0-" << capacity-1 << ")";
   throw err.str();
  }
 return Data[index];
 }

 // Assignment oper
 Vector<T>& operator = (const Vector<T>& right) {
   Data = new T[right.GetSize()];
  for(int i=0; i<right.GetSize(); i++)
   Data[i] = right[i];
  size = right.GetSize();
  return *this;
 }

    private:
 T *Data;
 int size; // Current vector size
 int capacity; // Max size of vector

 void Grow() {
  capacity+=CAPACITY_BOOST;
  T* newData = new T[capacity];
  for(int i=0; i<capacity; i++)
   newData[i] = Data[i];

  // Dispose old array
  Data = NULL;
  delete[] Data;
  // Assign new array to the old array's variable
  Data = newData;
 }
    };

The input file:

aero
asia
biz
cat
com
coop
edu
gov
info
int
jobs
mil
mobi
museum
name
net
org  <-- crashes when this line is read
pro
tel
travel

The error Visual Studio throws is:

    Unhandled exception at 0x5fb04013 (msvcp100d.dll) in Email4.exe: 0xC0000005: Access violation reading location 0xabababbb.
  • 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-17T22:43:17+00:00Added an answer on May 17, 2026 at 10:43 pm

    Also in the default ctor you do

    Data = NULL;
    capacity=INIT_CAPACITY;
    

    (EDIT: expanded explanation here)
    But never allocate the memory for Data. Shouldn’t it be:

      Vector() {
       Data= new T[INIT_CAPCITY];
       size=0;
       capacity=INIT_CAPACITY;
      }
    

    And remove is missing

    --size
    

    EDIT:
    Fellow readers help me out here:

    Data is of type T* but everywhere else you are assigning and allocating it just like T instead of T* . My C++ days are too long gone to remember whether using a T& actually resolves this.

    Also I can’t remember that if you have an array of pointers and destruct it, that the dtor for the single instances in the array are destroyed.

    Also in the assignment operator, wouldn’t you be copying the pinters? so you just have to rely on the fact the the instance where you copyid from is never deleted (because then your objects would be dead too).

    hth Mario

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.