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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:32:31+00:00 2026-05-23T14:32:31+00:00

Again, I’m trying to make a simple program. It will read some kind of

  • 0

Again, I’m trying to make a simple program. It will read some kind of board, at the size of RxC. Each items on the board are letters, separated with spaces. This is a sample board:

A B C
D E F
G H I

After that, it will read an integer N, and for next N lines, read a string and process them one by one based on the given board. But now, I’m facing a problem with how to read them. Here is the code :

#include<iostream>
using namespace std;

int r,c,el; char **arr;

int main()
{
    char *tes;
    int n;

    //start reading the puzzle
    cin >> r >> c; el=r;
    cout << el << endl;
    arr = new char * [3*(r+c)-6];
    for(int i=0;i<r;i++)
    {
        arr[i] = new char[c+1];
        for(int j=0;j<c;j++) cin >> arr[i][j];
        arr[i][c] = '\0';
    }
    for(int i=0;i<el;i++) cout << arr[i] << endl;

    cin >> n;
    while(n>0)
    {
        n--;
        cin >> tes;
        cout << tes << endl;
    }
}

I don’t know what’s wrong with this, it’s seems OK to me. However, it always get runtime errors. I’m using latest MinGW and gdb debugger. On gdb I saw something like

“received signal SIGSEGV. Segmentation
fault”

, and an 0xC0000005 error. I really have no idea what’s going on here. I’ve tried both iostream(cin&cout) and cstdio(scanf,puts,etc.)

P.S.: I declare the variables globally, because I will process them on a different function out of the main() function. I set the size of the “height” of the array to (3*(r+c)-6), not to the normal (r) is because I will use the same array to store another strings later.

  • 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-23T14:32:32+00:00Added an answer on May 23, 2026 at 2:32 pm

    In addition to the problems already noted by others, you haven’t allocated any memory for tes – it’s just a dangling pointer.

    Change:

    char *tes;
    

    to, e.g.:

    char tes[80];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Me again, Trying to learn some jQuery stuff. Now I'm building an AJAX search
Will I have to pay again? I have about 9 months left before renewal
I'm trying to get into java again (it's been a few years). I never
Again with the soap. I am trying to build a header using soap4r that
Again pulling my hair out due to some Flex/AS3 weirdness. The following code does
again. Right now I'm having issues with some pretty basic functionality in PHP. I
Again, I am new to JPA & Hibernation. I am trying to use JPA
Again a simple thing. I have a stylesheet that parses XML and XSL files.
Once again I need some help. I'm working with a table that contains 3
Again I'm trying to wrap my head around Objective-C and Cocoa. So I've posted

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.