A console GUI concept

I am trying to do a gui function that allows to create small GUI's using the console and that do the programmer a favor to manage his functions and thus easily, eitherway, i have 2 errors i have no idea how to solve, the pos does't go up to the top, and goes with 1 too low, also, when deselecting an option, its last letter will be doubled. Here is what i've got so far. Any toughts?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  #include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <conio.h>
#include <windows.h>

using namespace std;
void clear() {
    COORD topLeft  = { 0, 0 };
    HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(console, topLeft);
}
int getSlash(char a[255])
{
  int ss=0;
  for(int i=0;i<strlen(a);i++)
    if(a[i]=='/' && a[i+1]!='/')
      ss++;
  return ss;
}
void show(char opts[255],int vals[100])
{
  int j=0;
  for(int i=0;i<strlen(opts);i++)
  {
    if(opts[i]=='/' && opts[i+1]!='/')
    {
      cout<<endl;
      if(vals[j]==1)
        cout<<">"<<flush;
      j++;
    }
    else
    cout<<opts[i]<<flush;
  }
}
int gui(char opts[255])
{
  int vals[100];
  for(int i=0;i<getSlash(opts);i++)
  {
    vals[i]=0;
  }
  show(opts,vals);
  int pos=0;
  while(2)
  {
    int a=getch();
    clear();
    if(a==80 && pos<getSlash(opts))
      pos++;
    if(a==72 && pos>0)
      pos--;
    if(a==13)
      break;
      for(int i=0;i<getSlash(opts);i++)
      {
        vals[i]=(pos==i);
      }
      show(opts,vals);

  }
}
int main()
{
  gui("hello/bye/bye/hella/bb/hello");
  return 0;
}
Hello masecla33,

i have 2 errors i have no idea how to solve, the pos does't go up to the top, and goes with 1 too low

I have no real clue to what you mean here. Are you referring to "pos" as defined at line 46 and its use?

Two warnings my compiler gave me had to do with for loops for(int i=0;i<strlen(opts);i++). "i" is defined as an int but "strlen()" returns a "size_t", i.e., unsigned int. comparing an int to an unsigned int will work, but not the best way to this.

The other error dealt with "getch()" being outdated and wanted "_getch()" instead. Once I fixed this error the next compile told me that the function "int gui()" did not return a value. Fixing these errors allowed the program to run giving me each word on a separate line.

At this point the program looks like it works OK, but I need to understand the functions better.

The header file "iomanip" does not appear to be used right now.

My thoughts for right now.

Hope that helps,

Andy
Last edited on
You might find yourself happier playing around with NCurses / PDCurses.
Topic archived. No new replies allowed.