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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:04:06+00:00 2026-06-15T15:04:06+00:00

Compiler:gcc 4.5.2 Terminal:Xterm OS:Linux(x86) Ncurses 5.9 I am programming a text editor that uses

  • 0
  • Compiler:gcc 4.5.2
  • Terminal:Xterm
  • OS:Linux(x86)
  • Ncurses 5.9

I am programming a text editor that uses ncurses to graphicaly represent an array key_strokes[]. It is one dimensional so I use the macro INDEX(y*maxx+x) to point to the current position in key_strokes (key_strokes[INDEX]). y and x are the current coordinates in the terminal returned by the function getyx(stdscr, y, x) and maxx is the max amount of cols that can be in each row returned by the function getmaxyx(stdscr, maxy, maxx). The program works great until I press backspace, for some reason the value of maxx is set to zero after it reaches the switch below. This of course throws off INDEX limiting it to only the first “row” of the array.

The user’s key strokes are captured as int key_strokes. I use a switch case to check and see if it is an arrowkey, backspace, F12, etc. INDEX and maxx are defined as,

#define INDEX (y*maxx+x)
unsigned int maxx = 0;

Note I am also using cbreak(); noecho(); keypad(stdscr, TRUE);.

case KEY_BACKSPACE:
if (INDEX >= 0)
{
   for(i = INDEX; key_strokes[i] != '\0'; i++) {
   key_strokes[i] = key_strokes[i+1];
   }

   if (total_count > 0) {
   total_count--;
   }

   delch();
   if (x == 0) {
   move(y-1, maxx-1);
   }
   else {
   move(y, x-1);
   } refresh();
}
break;
  • 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-15T15:04:07+00:00Added an answer on June 15, 2026 at 3:04 pm

    Are you sure that key_strokes[] is null terminated?

    ’cause if it isn’t, the for loop will copy everything in memory to the previous cell, until it reaches 0. And if maxx or maxy are right before a 0 value, they will be set to 0.

    Imagine the following layout:

    | key_strokes[0] | key_strokes[...] |   key_strokes[n] | maxy | maxx | some_other_var |
    |            'v' |              'i' | non-null garbage |   23 |   80 |           '\0' |
    

    After pressing backsapce after ‘i’, it will be:

    | key_strokes[0] | key_strokes[...] |   key_strokes[n] | maxy | maxx | some_other_var |
    |            'v' | non-null garbage |               23 |   80 | '\0' |           '\0' |
    

    That could also explain why it’s maxy which is set to 0 when maxx is declared const (GCC doesn’t store the consts at at the same place in memory).

    To ensure that key_strokes[] is null-terminated, I’d suggest you to add this into your init section:

    memset(key_strokes, 0, sizeof(char) * size_of_key_strokes_array);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing some COM programming and my compiler is gcc. That means CComPtr is
I'm using Linux Ubuntu Intrepid Ibex and using as compiler the gcc , but
I have a source file that I can run via the terminal using gcc
Hi I have the following program. When I compile on the terminal gcc main.c
I am getting this compiler (gcc 4.5) warning: Formatter.cpp:23: warning: unknown conversion type character
I compiled this (gcc compiler) : #include< stdio.h> main() { unsigned char ch; FILE
I compiled this (gcc compiler): #include <stdio.h> main() { struct { a:1; b:2; }
I am using the GCC compiler but I want the to code the actually
I was trying to execute this code through gcc compiler: #include <stdio.h> int main()
I am working on a platform with a gcc compiler however boost cannot compile

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.