How to completely overwrite output in c - c

So I am working on this side project game kinda thing, and I want to put it inside of a border/box. I then want to print text constantly inside that border: adding text, removing it, changing it etc. I've looked far and wide, and cannot find anyway to print inside the box separately from the actual box.
My current implementation is to clear screen, and then reprint the entire box with new text using this:
printf("\e[1;1H\e[2J");
The issue with this is that I get this very obnoxious blinking effect, because every iteration of clearing my screen causes that portion of the screen to become black for a certain period of time.
So I am looking for a few solutions.
How to print a border separate from the print statement inside of it. I currently am implementing it like such:
printf("| | Hello There ||\n");
, and then repeating that all the way down to make a border.
How to completely overwrite the already outputted text so that this blinking effect can go away. So imagine \r removing a line, I want something like that, that removes the whole text and replaces it with a new set of text
How to change the location of where the user inputs into the console, so you can type into a box
Those are basically the only solutions I could think of, if you have any others I'd love to hear them
I also had a general question about c.
conio.h, graphics.h, windows.h and a few other headers don't work for my compilers. I use ubuntu, and they always come up with some error saying I can't use them. I appreciate someone explaining this to me.
Please let me know what you think, and if you need more info, I'll be sure to provide it
-Ryan

conio.h and windows.h are not standard Linux libraries, so they won't compile on Linux unless you install extra software. One solution would be to use a library designed for managing the screen like ncurses.

You can do that with loops and ASCII characters similar like that:
#include <stdio.h>
int main()
{
int i;
printf("\n\t\t═");
for(i=0;i<=20;i++)
{
printf("═");
}
for(i=0;i<=22;i++)
{
printf("\t\t║\n");
if(i==10)
{
printf("\t\t\tHello There \t\n");
}
printf("\t\t\t\t\t║\n");
}
printf("\t\t═");
for(i=0;i<=22;i++)
{
printf("═");
}
return 0;
}

Related

C programming issues, GTK assertion problem

I am posting this question because I have a problem with my beginner programming project.
I am new in the use of gtk and I am blocked by a problem that I wish to expose to you.
For my program to work I need to clear my store list and rewrite it, but when I run my gtk_list_store_clear(store) function my compiler displays an error of this type.
enter image description here
void actualize_index_of_rep()
{
int i;
GtkTreeIter iter;
for(i=0;i<rep_size;i++)
myRep[i].index=i;
gtk_list_store_clear(store);
for(i=0;i<rep_size;i++)
{
gtk_list_store_append(store,&iter);
gtk_list_store_set(store,&iter,0,myRep[i].name,1,myRep[i].tel,2,myRep[i].index,-1);
}
return;
}
For people who want the entire code he is here
enter link description here
And the save file
enter link description here
Thank you in advance for your time :)
I pulled down a copy of your program, built it, and ran it. I encountered the same issue. To be brief, after adding in some "g_printf" statements to track the process, I discovered that you had two functions called when a row is selected and the deletion button is clicked.
remove_from_prog();
remove_from_list();
When I scanned through the first function, I saw that it was saving a copy of the list out to your "save.data" file, omitting the selection that was deleted. The function then rebuilds the list and view. So, when the second function is called ("remove_from_list"), it can no longer find the row selection which then throws the error you see. The bottom line is that it appears that you do not even need the "remove_from_list" function.
Hope that helps.
Regards.

Implementing "tab completion" in RichEdit Winapi

This is a feature you see in a lot of IRC clients. Basically, if you type a string "Ad" and then hit tab the client will fill in the first matching nick (in the case of an IRC client) mathcing 'Ad' - so let's say it fills in Adam. But, like bash, if you keep hitting tab it should cycle through all the names containing "Ad" as a prefix.
I'm not quite sure how to implement this in the Wndproc for a RichEdit though. Specifically, when a user hits tab I need to get the current 'token', save it, and get all the prefixes and fill in the first. If he hits tab again I need to get the next prefix, and so on, but I need to empty the prefix list once I get a WM_CHAR that's not tab -- I think?
I'm wondering if there's some easier, less hacky way though, or if anybody has seen code that does this?
Thanks.
Useful though Remy's comments are, it seems to me that this question is more about what the logic should be to implement kind-of-bash-style auto-completion than anything else. On that basis, and based on what you posted, which I found slightly confusing, I think it should be something like this (pseudo-code);
int autocomplete_index = 0;
string autocomplete_prefix;
on_tab:
if (autocomplete_prefix == "")
{
autocomplete_prefix = current_contents_of_edit_field ();
autocomplete_index = 0;
}
auto autocomplete_result = get_autocomplete_string (autocomplete_prefix, autocomplete_index++);
if (autocomplete_result != "")
replace_contents_of_edit_field_and_move_caret_to_end (autocomplete_result);
else
beep (); // or cycle round
done;
on_any_other_char:
autocomplete_prefix = "";
If the rich edit control is embedded in a dialog, you also need to ensure that the dialog manager does not speak in and snaffle VK_TAB before you do. That normally doesn't happen for rich edit controls (although it does for regular edit controls - go figure) but if it does you can handle WM_GETDLGCODE appropriately in your WndProc (details on request).
And 'hacky'? Why? I don't think so. Sounds like a good idea to me.

How to draw flowchart for code involving opening from text file and reading them

like this code
fp1=fopen("Fruit.txt","r");
if(fp1==NULL)
{
printf("ERROR in opening file\n");
return 1;
}
else
{
for(i=0;i<lines;i++)//reads Fruits.txt database
{
fgets(product,sizeof(product),fp1);
id[i]=atoi(strtok(product,","));
strcpy(name[i],strtok(NULL,","));
price[i]=atof(strtok(NULL,","));
stock[i]=atoi(strtok(NULL,"\n"));
}
}
fclose(fp1);
These symbols sound too similar to differentiate their function,can anyone helps me by any method, or use names of shape according to this site http://www.breezetree.com/article-excel-flowchart-shapes.htm
REF:
Used a random online tool to generate this flowchart from your code. http://code2flow.com/
Study more about flowcharts here : http://creately.com/blog/diagrams/flowchart-guide-flowchart-tutorial/
See sample flowcharts here : http://www.conceptdraw.com/samples/flowcharts
Back in the days of FORTRAN, we used that hexagonal symbol on the page you linked to for the "DO" loop, which is basically the same as the modern "for" loop.
So, to draw the loop part of your program I would use that symbol, with a note inside like this:
for i = 0 --> (lines - 1)
Read this as "for i from 0 to (lines - 1)" with the increment of 1 implied by default.
Then the bottom-most box in the loop would have two arrows coming out of it: one straight down to the next statement, and one out the side heading back up to the side of the hexagon.
You could use the diamond to represent "if", but that can obscure the meaning of what you are trying to do, namely execute the loop a certain number of times.
BTW, I don't have high enough reputation yet to post images, so you will have to either follow the link or visualize a hexagon whose center section has been stretched horizontally.
Update: I see that, while I was typing my answer, thecbuilder has also answered this, with a real flowchart. His illustrates how the loop actually works internally, which is fine; mine was intended to show the meaning of the loop on a slightly higher level of abstraction.

redrawing an array in C

I just started with C, but I had some knowledge of PHP, so I decided to do some 'more complicated' stuff, as for a beginner :)
I used two nested loops to print an 50x50 array. It isn't very slow, but I included a movement with arrow keys to it to move one symbol, X (player) around the array. Every time a move is made, whole array needs to be refreshed, which I did by:
system("cls");
for(x=0;x<50;x++)
{
for(y=0;y<50;y++)
{
printf("%c",table[x][y]);
}
printf("\n");
}
Which is very sloppy solution and whole array 'blinks' while it refreshes after every move.
Is there any more efficient way of doing that in C?
You would probably have to use some sort of shell graphics library like ncurses to move stuff around your array without it blinking when you redraw it. There's not really a simple way to avoid that when you're just using printf to display your grid as output.
I assume you're using Windows (because of the cls).
Maybe ANSI.SYS escape sequences are the simplest way without a library.
You can probably avoid flickering if you move the cursor and overwrite the display contents without clearing the old contents.
There's an example on "Reading and Writing Blocks of Characters and Attributes" with the Win32 Console:
http://msdn.microsoft.com/en-us/library/ms685032%28v=vs.85%29.aspx
Edit: explained the link.

TeleUSE window not resizing

We're porting an application from Tru64 to SLES11 and the part that I'm working on right now is a GUI written with TeleUSE.
The problem that I'm encountering is that one of my XmBulletinBoardDialogs has only half the size on LINUX compared to Tru64. I've tried to change the height in the pcd file and the generated c code looks alright but has no effect:
XtSetArg(args[n], XmNheight, 800); n++;
Any appearance changes that I've tried had no effect also..
Are there known problems or changes in functionality between the platforms or should I search for constraints from parent windows (then how would they look like?)? I'm new to TeleUSE so any hint on a probable source for the problem would help.
The size of the window was set by the input string "\n\n\n\n TEXT \n\n\n"
The problem was that apparently the parsing of the string is working differently with the function "XmStringCreateLtoR". I had to add spaces between the \n's for the line breaks to have an effect

Resources