Duoas 1,025 Postaholic Featured Poster

Wait, is this a console (text) program or a Windows (GUI) program?


In either case, you will have to add "event listeners": code that checks for input from the keyboard and the mouse. If a button is pressed, add the appropriate digit into the current number or invoke the appropriate function. If a key is pressed, add the appropriate digit into the current number or invoke the appropriate function.

In a Win32 console program, you'll have to either use the Curses library or use GetConsoleInput after using SetConsoleMode to add mouse events to the input mask.

In a Win32 GUI program, you'll add OnClick and OnKeyDown events to your application, or if you are writing your own WindowProc, listen for WM_LBUTTONDOWN and WM_KEYDOWN messages.

This is all for Win32, you may have noticed. If you are using Linux or DOS let me know.

Good luck.

Duoas 1,025 Postaholic Featured Poster

A .COM file is a 16-bit image file. You'll need a 16-bit compiler and a 16-bit linker.

I presume you are talking about an executable file, right? .COM as opposed to .EXE?

Duoas 1,025 Postaholic Featured Poster

libm.a

Duoas 1,025 Postaholic Featured Poster

There is no function (AFAIK) that allows you to hook every thread in a single process at once...

I would add the hook as part of the new thread startup procedure (either by the caller when creating the thread or just as the first thing the new thread does).

Good luck.

Duoas 1,025 Postaholic Featured Poster

The math library is just compiled code. It is in the ~lib/ directory.

When you #include <math.h> you are only telling the compiler what the things (functions) in the math library look like. But that doesn't automatically link those functions into your program. You have to do it with the appropriate command. For example, if I were using the GCC, I'd say: gcc myprogram.c -lm where that "-lm" is the compiler directive for Link Math library.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I used to go ask my father for the meanings of words all the time. After a while he took me to the bookshelf and showed me where the dictionary was.

Not only do you get the satisfaction of figuring something out yourself, you remember it better. Then you get satisfaction from helping someone find the information, rather than giving it to him.

Of course, after a while people stopped understanding the words I was using...

(Alas, I still know less than I'd like... ;-)

Duoas 1,025 Postaholic Featured Poster

As you can see from the number of postings about this so far, quite a few people have been working on this. I have seen two text-only, ASCII-art versions, and one windows application using images. Add a "7-segment" font to that repertoire and you have a lot of choices...

Duoas 1,025 Postaholic Featured Poster

You solved this?

Mind posting a quick overview of what you did so others can learn?

Duoas 1,025 Postaholic Featured Poster

Why don't you click the link I gave you?

Turbo C++ Explorer is for creating Windows applications. You also get Borland's VCL. So you can draw on and display stuff using a canvas object.

The easiest way would be to drop a tImage component on your form and use its canvas property to draw on it.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

If it is core-dumping you still need to potty-train it.

Google "linked lists" and read more to learn how to fix your problems. (They are all caused by an improperly-coded linked list.)

Also, your setHead() method is very dangerous: you should not have methods that let things outside your class mess around with its private data.

Hope this helps.

WaltP commented: Great imagery!! +11
Duoas 1,025 Postaholic Featured Poster

For a simple, Turbo C text editor, I assume that your professor wants just a text-mode, <conio.h>, text editor?

The only things you really need to worry about are:

  1. How is the file stored in memory? As a linked list of lines? Or buffered? (I recommend the first.)
  2. What are the commands to do editing? (You might want to draw a status-line at the top of the screen saying something like: F1:[I][/I]Open F2:[I][/I]Save F10:[I][/I]Quit etc. Remember arrow keys, etc.
  3. You'll need functions to draw the visible stuff to the screen, move the cursor up/down/left/right, insert/delete/overwrite text, scroll up/down, save the file, load the file, etc.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Actually, the folks at <whoever owns borland nowdays> have brought back the "Turbo" moniker... So if you go download Turbo C++ Explorer you wouldn't have to resort to BGI graphics at all...

JSYK.

Duoas 1,025 Postaholic Featured Poster

I didn't say he had malicious intent. (In fact I don't really think he does.)

What I said was he'd have more fun doing something constructive.

Duoas 1,025 Postaholic Featured Poster

And secondly, if you are going to ask for advice you can't ignore the advice given you and complain things still don't work. I didn't walk into your house and tell you to sit. I answered your question.

Duoas 1,025 Postaholic Featured Poster

You know, cosmos22, playing around with another person's computer really isn't funny. In fact, it is the kind of crap warez dorks and wannabes do.

Why don't you do something that will be both appreciated and cool?

Like write a simple video game.
Or write a cool screen saver you and your friends can use.

Both of these are impressive tasks.

Duoas 1,025 Postaholic Featured Poster

You are getting lost on syntactic sugar. ([B]define[/B] (foo x y z) (+ (- x y) z)) is sugar for: ([B]define[/B] foo ([B]lambda[/B] (x y z) (+ (- x y) z))) Likewise, inside the body of a lambda, using ([B]define[/B] (bar q) (* q (+ q 1))) ... is sugar for: ([B]letrec[/B] ((bar ([B]lambda[/B] (q) (* q (+ q 1))))) ...) What I suggest is replacing the lines: ([B]if[/B] ([B]null?[/B] lst) lst with: ([B]if[/B] ([B]not[/B] ([B]null?[/B] lst)) and see if that works. (I'm not sure if it will or not...)

Duoas 1,025 Postaholic Featured Poster

It is not working because you failed to obey my advice.

Read up on istream::ignore() to find out why it fails.

Duoas 1,025 Postaholic Featured Poster

Post what you've got and what part of it is giving you trouble.

Duoas 1,025 Postaholic Featured Poster

It just moves data around.

Check out the Wikipedia for a pretty good opcode reference.

Also, I didn't realize you could use jr $ra in main... I'll have to check that out. (Generally programs terminate using the exit syscall.)

Good luck.

Duoas 1,025 Postaholic Featured Poster

If by "a few degrees" you mean something other than 90, 180, or 270, then you can't (not without some fancy magic tricks).

If by "a few degrees" you mean exactly 90, 180, or 270, then maybe. What OS and WM are you using? Also, what is your video hardware?

Duoas 1,025 Postaholic Featured Poster

You are on the right track, but you need to think about what each segment should look like.
For example, you could use 4 by 3 character grids for each segment, and the numbers as

_       _   _       _       _   _   _  
| |   |  _|  _| |_| |_  |_    | |_| |_| 
|_|   | |_   _|   |  _| |_|   | |_|   |

All segments would be:

_  
|_| 
|_|.

All you need to know is the upper-left hand coordinate. For example, to display a zero:

procedure zero( x, y: integer; dp: boolean );
  begin
  gotoxy( x, y    );  write( ' _  ' );
  gotoxy( x, y +1 );  write( '| | ' );
  gotoxy( x, y +2 );  write( '|_|' );
  if (dp) write( '.' ) else write( ' ' )
  end;

Notice how I added a condition to draw that decimal point.

If you want to treat it as if it were an actual 7-segment display, you could write just one procedure to display it:

procedure draw7seg( x, y: integer; bits: byte );
  begin
  gotoxy( x, y );
  write( ' ' );
  if bits and $01 then write( '_' ) else write( ' ' );
  write( '  ' );
  gotoxy( x, y +1 );
  { finish filling in the correct code here}
  end;

The bits would be bit zero for A, bit one for B, ..., bit 6 for G, and bit 7 for DP.

The codes for the numbers are easily stored …

Duoas 1,025 Postaholic Featured Poster

Between lines 11 and 12 put cin.ignore( numeric_limits<streamsize>::max(), '\n' ); The stream >> operator only reads what you ask it to, and leaves everything else behind in the input buffer. However, whenever dealing with user input you must expect that the user will press the ENTER key after everything you ask him to enter.

getline() reads everything except the ENTER key, stores it in a string, then reads and throws away the ENTER key.

cin >> anything, in contrast, only reads anything, and leaves everything else (including that pesky ENTER key) in the input stream. So the next time you call getline(), it does what it did before, reading '' and sticking it in to a string, then reads the ENTER key and throws it away.

So, after using >> you must explicitly read and throw away that ENTER key so that it isn't still there the next time you try to get input from the user.

Hope this helps.

Roebuc commented: Thank you for explaining it so clearly! +1
Duoas 1,025 Postaholic Featured Poster

The error you have has nothing to do with my code. undefined reference to 'winmain@16' means that you did not define a main function. Which means that you did not use the code I gave you in an application. Go to File -> New -> Windows Application to create a new project, write your forms, etc. and somewhere in there copy in the functions I gave you. Only then can you use them.

The second error is because of the first.

Duoas 1,025 Postaholic Featured Poster

None of the code I posted is a complete program. They are utility functions.

[EDIT] In other words, copy and paste them into your program and use them at the appropriate moment. For example, if you just want the console window to disappear, start your program and either FreeConsole or HideConsole.

Duoas 1,025 Postaholic Featured Poster

You might want to remember to load (E)DS at the beginning of your program.

All the functions you are using (with 'call') have a register call type, meaning that arguments are passed in registers. Hence, to settextcolor( attribute: byte ) the attribute must first be placed in AL (as you have done).

Make sure to keep the two parts (loading the registers and calling the function) together for each function. Use commentary to help:

; Set the text attribute to colors[esi]
	mov al, [esi]
	call settextcolor

	; Write a '#' to show the colors
	mov al, '#'
	call Writechar

etc. The reason I want you to do this is so that you don't make mistakes like you did with gotoxy (which should take two arguments: one in AX and one in BX, if I remember correctly).

Be careful how you use (E)SI. When you change it for the inner loop, you completely loose your place in the outer loop. I would recommend pushing and popping SI and CX at the same places in the code.

; Prepare to enter the inner loop
	push si, cx

	...

	; Prepare to return from the inner loop
	pop cx, si

The last thing to think about is how a text color attribute is stored. Remember: four bits for the background and four bits for the foreground. You'll have to use some bit manipulations (shift and add) to combine the current foreground color with the current background color, then settextcolor and …

Duoas 1,025 Postaholic Featured Poster

There are two basic ways.

First, you could simply FreeConsole to get rid of the console window, then AllocConsole to get a new one.

Better yet though, is to use ShowWindow:

#include <string>
#include <windows.h>

const char STR_CONSOLE_WINDOW_CLASS[] = "ConsoleWindowClass";

std::string GetConsoleTitle() {
  unsigned long length;
  std::string result( 1000, '\0' );
  length = GetConsoleTitle(
    const_cast<char *>( result.c_str() ),
    1000
    );
  result.resize( length );
  return result;
  }

void HideConsole() {
  HWND hConsole = FindWindow(
    STR_CONSOLE_WINDOW_CLASS,
    GetConsoleTitle().c_str()
    );
  ShowWindow( hConsole, SW_HIDE );
  }

void ShowConsole() {
  HWND hConsole = FindWindow(
    STR_CONSOLE_WINDOW_CLASS,
    GetConsoleTitle().c_str()
    );
  ShowWindow( hConsole, SW_SHOW );
  }

Well, that should do it... As usual, I just hacked this in so don't everyone complain too much if it needs a slight tweak to work.

You may want to use SetConsoleCtrlHandler() to keep the user from terminating your application when the console window is closed. A handler might look something like:

BOOL my_console_ctrl_event_handler( DWORD dwCtrlType ) {
  std::cout
    << "\n+-----------------------------------------------+"
    << "\n|  HEY YOU THERE! CLOSING ME ENDS THE PROGRAM!  |"
    << "\n+-----------------------------------------------+"
    << "\n"
    << "\nTo make this window disappear, select"
    << "\nFile -> Hide Console from the main window's menu."
    << std::endl;
  return dwCtrlType == CTRL_CLOSE_EVENT;
  }

(And if you use this message, don't forget to add a "Hide Console" command to the File menu.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Ah, I misunderstood the original post.

Duoas 1,025 Postaholic Featured Poster

It's a joke. Google around "infinity" and "cardinality".

Duoas 1,025 Postaholic Featured Poster

Actually, it is possible. You need to use token concatenation. #define DEFINE_FUNC( n ) void func_ ## n() You would use it in the normal way: DEFINE_FUNC( 12 ); The preprocessor would turn that into: void func_12(); While I can't imagine why you want to do this, there are, in fact, legitimate reasons to do token concatenation (which goes a long way into explaining why the preprocessor can do it at all).

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Two nested infinite loops? Is that what you'd call an alpha loop?

Duoas 1,025 Postaholic Featured Poster

Is this a trick question?

(The answer depends on the machine's addressing scheme ;) )

Duoas 1,025 Postaholic Featured Poster

The theory on recursion over lists is actually pretty simple. The idea is this:

If you can do something to the head of a list in relation to the rest of the list, you can do it to the whole list.

Let's have an example. Suppose you have a list of numbers. 1 4 -7 19 42 0 8 The question I'll pose is: What is the sum of the numbers in the list?

We'll need a consumer function: one that takes a list of numbers and converts it into a single number. [B]function[/B] sum_list( ls: [B]array of integer[/B] ): [B]integer[/B]; Initially, of course, we call our function with the whole list: sum_list( [1, 4, -7, 19, 42, 0, 8] ); The sum can be considered thus: 1 + sum_list( [4, -7, 19, 42, 0, 8] ); Consider for a second what we did. The sum of the whole list is the same as adding the first element of the list to the sum of the rest of the list.

So then, what is the sum of the rest of the list? You guessed it: the same darn thing. Keep doing it until the list runs out and you'd get something like: 1 + 4 + -7 + 19 + 42 + 0 + 8 + sum_list( [] ); At this point, we can safely say that the sum of nothing (the empty list) is nothing (zero). So sum_list( [] ); should return zero.

In mathematics, what …

Duoas 1,025 Postaholic Featured Poster

Ah, yes, I forgot to address your question. Sorry. :$

unsigned int corresponds to EAX.
unsigned short corresponds to AX.
unsigned char corresponds to AL.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You can only delete one file at a time. If you have a list of files, you can iterate through the list and delete each file in turn.

vector<string> file_list;
int num_files_not_deleted = 0;

for (int i = 0; i < file_list.size(); i++)
  if (!DeleteFile( file_list[ i ].c_str() ))
    num_files_not_deleted++;

if (num_files_not_deleted)
  cout << "Could not delete all the files." << endl;

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You have a couple of problems.

Your "display the array" routine (intarray) is perfect. Your "search the array" routine (exist) should look almost exactly like it. (But it doesn't).

The found variables should be boolean. Also, the found parameter should be a var parameter. The procedure type should be: [B]procedure[/B] exist (a: [B]array of integer[/B]; longar, num2find: [B]integer[/B]; [B]var[/B] found: [B]boolean[/B]); Frankly, I'd make it a function instead: [B]function[/B] exist (a: [B]array of integer[/B]; longar, num2find: [B]integer[/B]): [B]boolean[/B]; Also, a couple of suggestions:
It is OK to say just writeln; .

At the bottom, use an if..else statement:

if found
    then writeln( 'Found' )
    else writeln( 'Not Found );

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You have to call ADC after each ADD. (The carry flag is only one bit deep.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You need to get a good Win32 reference.

The function you want is BOOL RemoveDirectory( LPCTSTR lpPathName ); The directory must be empty and your program must have permissions to delete it. If the function fails it returns zero, else it returns non-zero.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I would not hire you if I saw that code.

Listen to VernonDozier and niek_e. They know what they are talking about.

Your program is a C program (not C++), so you shouldn't be using C++ stuff in it.

Duoas 1,025 Postaholic Featured Poster

Alas, (I hope you are sitting down), the error is explained here:
C++ FAQ Lite: Why am I getting errors when my template-derived-class uses a nested type it inherits from its template-base-class?

I've never encountered this problem before (I've never tried to do what you are doing) but I'll poke around a bit and see if there is a solution.

Unless, of course, someone else here knows the answer...

Duoas 1,025 Postaholic Featured Poster

You'll need to make yourself a DLL that has the hook callback function. Google "system hook" for information.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

No. INC affects O, S, Z, A, and P only.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes, you made me look it up myself. See here.

So, apparently the << operator knows how to print a (void *), which is the default promotion for most pointer types... (I think)

Duoas 1,025 Postaholic Featured Poster

It is because of default type promotion.

&integer is an (int *), which has no << overload, so it gets converted to an integer type and displayed.

Likewise, &letterarray is an (char[11] *), so it gets converted to an integer type and displayed.

However, &letter is a (char *), which does have a << overload (to print strings), so << tries to print a string. You are lucky it doesn't crash your program. You can get the correct default promotion by first casting to some pointer type that doesn't have a << overload (or at least properly prints the pointer type): cout << letter << "\t\t" << [B]static_cast<void *>([/B]&letter[B])[/B] << endl; Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The OP already knows Alt-ENTER, and has complained that the resolution is poor, and asked how to fix the fixed-size Windows window.

I missed the 60k space question (sorry) but this is an old, 16-bit DOS program. You cannot increase the operating space.

Using WIDTH 40 is hardly helpful for increasing the character resolution.
The SCREEN modes listed don't help either. Mode 0 is MDI text. mode 1 is CGA 4 color graphics, 320x200 pixel, and mode 2 is 2 color, 640x200 pixel graphics --both of which are likely lower resolution than mode 0. The highest resolution graphics mode you can get with GWBASIC is SCREEN 9, which probably won't work... Read more here. In any case, switching to a graphics mode is not a good option unless you are doing graphics.

Duoas 1,025 Postaholic Featured Poster

Don't use void main() .
Always use [B]int[/B] main() .

In "List.h" the Traverse() method is (incorrectly) prototyped as void Traverse( DataType, int& ) . In "List.cpp" it is (correctly) defined as [B]bool[/B] Traverse( DataType, int& ) .

Please don't use leetspeak or other weenie talk. (Be kind to those for whom English is not their first language.)

Hope this helps.

SpS commented: :) +4
Duoas 1,025 Postaholic Featured Poster

Looks like you did a good job. :)

Duoas 1,025 Postaholic Featured Poster

If you just double click the OnShow property in the Object Inspector (sorry to keep using Borland terminology) the IDE should auto-create an event procedure for you. Borland would name it "FormShow".

Duoas 1,025 Postaholic Featured Poster

OnShow is a property. (Essentially it is a function pointer.) Your function should be named something like void Form1::FormShow( TObject *Sender ); and then you set OnShow = FormShow.

For each form, the OnCreate handler (which it looks like you have named "InitializeComponent"?) should only fire once. Your form is created at the beginning of the program, and no matter how many times you show or hide it, it is only destroyed when the program ends.

It is possible to do things differently, but I wouldn't worry about that for now...

If this doesn't help then please post some complete code that demonstrates your problem...

Duoas 1,025 Postaholic Featured Poster

Why do you keep opening and closing your outfile? (You never do that with cin...)

Get rid of every line that says outfile.open( ... ); and every line except the last that says outfile.close(); , and try it again.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Place your cursor on the name "FormatFloat" and press F1. You'll get a help page telling you everything you need to know about the function. Mine says:

Formats a floating point value

Unit
SysUtils

Category
floating point conversion routines [B]function[/B] FormatFloat([B]const[/B] Format: [B]string[/B]; Value: Extended): [B]string[/B]; Description
...

So you'll want to make sure the first argument is a string and the second argument is a floating point type (single, double, extended, real, or real48).

Good luck.