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

  • Home
  • SEARCH
  • 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 8892445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:59:57+00:00 2026-06-14T22:59:57+00:00

/* INCLUDES & DEFINES */ #define _CRT_SECURE_NO_WARNINGS 1 #include stdlib.h #include stdio.h #include string.h

  • 0
/* 
INCLUDES & DEFINES
*/
#define _CRT_SECURE_NO_WARNINGS 1

#include "stdlib.h"
#include "stdio.h"
#include "string.h"

#define N 10

#define LINE_LENGTH (65537*6) /* assuming we deal with integers. 65536 is the largest integer. each number in line offers a ' ' or '\0' and each number consists of 5 chars max.*/
#define STR_MAIN_ERROR_MSG "error occured while attempting to read data from file. aborted!\n"
#define STR_MENU "(a) print double-dynamic array.\n(b) add new number.\n(c) add new column.\n(d) remove last number.\n(e) remove last column.\n(q) quit program.\n\nEnter your choice: "
#define STR_MENU_INPUT_ERROR "Wrong Choice, try again.\n"
#define STR_MENU_QUIT "End of program, Thank you & good bye...\n"
#define STR_MENU_SHORT "Menu: ...\nEnter your choice: "
/*
FUNCTION DECLARATIONS
*/
int allocate_subarray(int**, const int);
int parse_line_data(char*,int**,const int);
int read_file_successful(int**);
void start_menu(int**);
void terminate(int**);

void funcA(const int**);
void funcB(int**);
void funcC(int**);
void funcD(int**);
void funcE(int**);
/*
MAIN FUNCTION BODY
*/
int main(){
    int *Array[N]={NULL};
    if ( read_file_successful(Array)) start_menu(Array);
    else printf("%s",STR_MAIN_ERROR_MSG);
    return 0;
}
/*
OTHER FUNCTION BODIES
*/
int allocate_subarray(int** p, const int size){
    *p=(int*)malloc(sizeof(int)*size);
    return (p!=NULL);
}
int parse_line_data(char *S, int **A, const int i){
    int j;
    int size=atoi(strtok(S," "));
    if(!allocate_subarray(&A[i], size)) return 0;
    for(j=0; j<size; j++) A[i][j]=atoi(strtok(NULL," "));
    return 1;
}
int read_file_successful(int** A){   /* <----- STACK OVERFLOW HAPPENS HERE. */
    FILE *f=fopen("input3.txt", "r");
    if(f){
        char line[LINE_LENGTH*N];
        int i;
        for(i=0; fgets(line,sizeof(line),f) && i<N; i++) 
            if (!(parse_line_data(line, A, i))) return 0;
        fclose(f);
        return 1;
    }
    return 0;
}
void start_menu(int **A){
    char choice;
    printf("%s",STR_MENU);
    do{
        scanf("%c",&choice);
        while(getchar()!='\n');
        switch(choice){
            case 'q': terminate(A); printf("%s",STR_MENU_QUIT); return;
            case 'a': funcA(A); break;
            case 'b': funcB(A); break;
            case 'c': funcC(A); break;
            case 'd': funcD(A); break;
            case 'e': funcE(A); break;
            default: printf("%s",STR_MENU_INPUT_ERROR);
        }
    } while(printf("%s",STR_MENU_SHORT));
}
void terminate(int **A){
    int i;
    for(i=0; i<N && A[i]; i++) free(A[i]);
}
/**/
void funcA(const int **A){}
void funcB(int **A){}
void funcC(int **A){}
void funcD(int **A){}
void funcE(int **A){}

Doing this favour for a friend, a basic program that reads lines from a text file, and converts them into integers stored in malloc allocated arrays (sizes given in text too). problem is, long time no C. debugging this beauty, and it gives me a stack overflow error message in the spot I commented for you. Tried different variations for the function parameter: int* A[] , int* A[N].. still trips me up @run-time.

  • 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-14T22:59:58+00:00Added an answer on June 14, 2026 at 10:59 pm

    You’re allocating N * LINE_LENGTH stack space in read_file_successful(). Do the math. Thats 10 * 65537 * 6, or 3932220 bytes. thus blowing your stack.

    char line[LINE_LENGTH*N];
    

    where LINE_LENGTH is 65537*6 and N is 10.

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

Sidebar

Related Questions

#include<stdio.h> void main(){ int x,y,z; x=y=z=1; z=++x||++y&&++z; printf(%d %d %d \n,x,y,z); getch(); } the
#include<stdio.h> void function(int); int main() { int x; printf(Enter x:); scanf(%d, &x); function(x); return
#include<stdio.h> #include<time.h> int main() { clock_t start; double d; long int n,i,j; scanf(%ld,&n); n=100000;
consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
//Hydroelectric Dam Helper #include <stdio.h> #define GRAV 9.80 #define EFINC 0.9 #define EFINC2 90
#ifndef _ClientSocket_H_ #define _ClientSocket_H_ #include Includes.h #include LOGMSGs.h class cSocket { public: cSocket(); bool
Apple's Technical Q&A on addressing flickering (QA1650) includes the following paragraph. (Emphasis mine.) You
I've copied all my category files & header includes to the new Xcode project,
I have the following code: $(document).ready(function() { $.getJSON('../includes/_quiz.php?class_id=163&course_id=183',function(data){ $.each(data,function(k,v){ questions[k] = v.question; answers[k*4] =
I am developing a system which include a server app & a client app,

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.