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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:23:55+00:00 2026-06-01T17:23:55+00:00

I have the following code: (please pardon the length of this code). I am

  • 0

I have the following code: (please pardon the length of this code). I am trying to access elements of a vector within a vector.
table_info* get_table_info function gets the values of the table_info vector for a particular table. When I try to check the values of column_info vector, I an encountering a strange error, where the program suddenly terminates.

typedef struct _column_info {
char name[20];  // columns name
int type; // 0:INT, 1: CHAR
int size;
int offset; // start position
} column_info;

typedef struct _table_info {
char name[20];
int column_count;
char columns[100];
vector <column_info> col;   //col[0], col[1]...
char primary_key[5];
int recordsize;
int totalsize;
int records;
} table_info;

vector <table_info> v;

void create_table(char* tablename, struct columns *cc , int num_col, char* pkey) {
    char* new_columns;
new_columns = (char*)malloc(256*sizeof(char));
strcpy(new_columns,"");

int len = 0;
len = num_col;

for ( int i=0 ; i < len ; i++ )
{
    strcat(new_columns, cc[i].c_name);
    strcat(new_columns, ":");
    strcat(new_columns, cc[i].c_type);

    if ( strcmp(cc[i].c_type,"char") == 0 )
    {
        strcat(new_columns, "(");
        strcat(new_columns, cc[i].c_size);
        strcat(new_columns, ")");
        record_size = record_size + atoi(cc[i].c_size);
    }
    else
        record_size = record_size + 4;

    if( i != (len-1) )
        strcat(new_columns, ",");
}

    table_info new_table;

        strcpy(new_table.name, tablename);
        strcpy(new_table.columns, new_columns);
        strcpy(new_table.primary_key, pkey);
        new_table.recordsize = record_size;
        new_table.totalsize = 0;
        new_table.records = 0;

        v.push_back(new_table);

    column_info cols;
    int offset = 0;
    for(int x=0;x<num_col;x++)
    {
        strcpy(cols.name, cc[x].c_name);
        if ( strcmp(cc[x].c_type,"char") == 0 )
            cols.type = 1;
        else
            cols.type = 0;
        cols.size = atoi(cc[x].c_size);

        cols.offset = offset;
        offset += cols.size;

        new_table.col.push_back(cols);
    }

table_info* table_info;
    table_info = get_table_info(tablename);
    int offset2=0;
    int size2 = 0;

    for (int i = 0; i < num_col ; i++)
    {
     offset2 = table_info->col.at(i).offset; // ERROR: ABNORMAL PROGRAM TERMINATION
      printf("offset:%d\n",offset2);
      size2 = table_info->col.at(i).size;
    }
    }

table_info* get_table_info(const string& tablename)
{
printf("table info \n");
    for (int i = 0; i < (int) v.size(); i++)
     {
       if (strcmp(v.at(i).name, tablename.c_str()) == 0)
    return &v.at(i);
     }
     return NULL;
  }

Any idea why this program terminates? Please help.

  • 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-06-01T17:23:56+00:00Added an answer on June 1, 2026 at 5:23 pm

    The Problem is that this code:

    v.push_back(new_table);
    

    is called before the columns have added to the table. At this time the “col”-collection is empty. Then push_back pushes a copy of your table_info instance to the vector (of course with the empty col-vector). So if you add the columns it is not added to the instance in your vector but to the local instance instead. And since num_col is greater than zero it throws an exception if you try to access the columns on that line, since table_info is the instance which is stored in the vector (the one with the empty col):

    offset2 = table_info->col.at(i).offset; // ERROR: ABNORMAL PROGRAM TERMINATION
    

    The solution is to move the push_back code down, right before you call get_table_info (or after adding the columns, if you will):

    // ... 
    v.push_back(new_table);
    
    table_info* table_info;
    table_info = get_table_info(tablename);
    // ... 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code in JavaScript function checkEntries() { if(document.getElementById(username)== && document.getElementById(password).value==) { alert(Please
Pardon the length, please. Also, this is a completely hypothetical, off-the-cuff situation and code
Please can someone help? I have the following code which uploads a file to
I'm a newbie so please be patient. I have the following code retrieving the
am new here. i have a slight problem; PLease look at the following code
In our code I have the following, for now please ignore the //* bits;
Learning a bit about Linq. I have the following code: (Please excuse the pathetic
I have the following code: HTML: <label id=copyAddress class=copyAddress onclick=CopyAddress(this);> Copy Address </label> JS:
I have the following code : do{ Console.Write(Please Input a Value: ); userInput =
I have the following code, simple I know (please feel free to recommend improvements)

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.