Hey Guys,

I need some help figuring something out for an assignment.

The assignment is basically about creating a editing program to edit a single char string on the console, everything has been coded and works without a hitch except for one part.

I can only display a certain number of elements at a time and need to be able to scroll through the array, I have coded the scrolling part ie. moving the cursor forward one element when the right arrow key is press and moving back one element when the left arrow key is pressed.

My problem is I am not sure how to display a limited number or character and still scroll through the whole array with out creating a smaller array and copying the displayable characters and displaying that on the screen.

I don't need source code just a hint or tip is perfect.

Recommended Answers

All 5 Replies

Just use an index into the array and output one character with putchar() at the correct screen location.

I tried that already tried that its just looping infinity and printing out junk.

Isn't there a function similar to fgets that I can use?

To make my problem a little clearer:

I have an array with the following char a[50] = "abcdefghijklmnopqrstuvwxyz" and I can only display 10 elements abcdefghij but press the right arrow key and the display should update to show bcdefghijk .

How would I be able to do this?

I repeat. Output a character at a time. In addition, stop when you reach 10.

>but press the right arrow key and the display should update
That's not possible with standard C. The line buffering in your console prevents your program from accessing input like arrows or function keys (nor can you modify something that has already been printed onscreen). To be able to accomplish that, you'll need to use system-specific API calls.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.