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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:25:22+00:00 2026-06-14T23:25:22+00:00

For my homework it is given one dimensional array and i have to convert

  • 0

For my homework it is given one dimensional array and i have to convert it in a two dimensional array. The two dimensional array has 2 for the number of columns, because i have to represent the one dimensional array as pairs(the value of the number, the number of appearences in the array).
This is what have tried. The error appears on the last 2 lines of code: access violation writing location 0xfdfdfdfd.

#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{
    const int NR=17;
    int arr[NR]={6,7,3,1,3,2,4,4,7,5,1,1,5,6,6,4,5};
    int **newArr;
    int count=0;
    int countLines=0;
    int searched;
    for(int i=0;i<NR;i++)
    {
            newArr=new int*[countLines];
        for(int i=0;i<countLines;i++)
        {
            newArr[i]=new int[2];
        }
        searched=arr[i];
        if(i>0)
        {
            for(int k=0;k<countLines;k++)
            {
                if(newArr[countLines][0] == searched)
                {
                    searched=arr[i]++;
                }

                for(int j=0;j<NR;j++)
                {
                    if(searched==arr[j])
                    {
                        count++;
                    }
                }
                countLines++;
            }
        }
        else
        {
            for(int j=0;j<NR;j++)
            {
                if(searched==arr[j])
                {
                    count++;
                }
            }
            countLines++;
        }

        newArr[countLines][0]=searched;
        newArr[countLines][1]=count;
    }
}
  • 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-14T23:25:23+00:00Added an answer on June 14, 2026 at 11:25 pm

    First you are using newArr in the first loop before allocating it any memory. You cannot dereference a pointer which owns no legal memory. It results in undefined behavior.

    Secondly in the last part, you are allocating newArr a memory equal to countLines thus.

    newArr = new int*[countLines] ;
    

    It means that the indices in the first dimension of newArr are 0------>countLines-1. Doing newArr[countLines][0] = searched ; is again undefined. Make it newArr[countLines - 1].

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

Sidebar

Related Questions

I have a homework question that says: Problem 1: Given the array [ 22
I have a homework that include a new operation (a [n] b), given: a
I have been given a homework assignment where I need to create a captcha
For homework we have been given the bathroom synchronization problem. I have been struggling
I've been thinking about this homework question for a bit now. Given an number
for starters, I did have a look at these questions: Given an array of
In an HTML page, I have three blocks: two textboxes and one inline SVG,
I have one question about writing a dictionary given a file. I have done
I've been given the homework to graph the function x^3 and 3^x in one
This task was actually given to us as homework, but the requirement in the

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.