Duoas 1,025 Postaholic Featured Poster

I'm always dinking with my PATH variable at the command prompt. But the supplied windows "path" command is (and has always been) pathetic.

Well, after my latest episode of typing "path" and getting 6!!! lines of clutter I had had enough. So I wrote this little utility that lets me do all the things I always want to do, and a few other things thrown in.

Get it here. (Download links are at the bottom of the page.) It should work on any 32-bit version of Windows.

Available as a binary or as full source code.

It works by temporarily injecting executable code in its parent's process (which should be cmd.exe), so if you are running an anti-virus it will complain at you the first time you run it. This is the only way to non-permanently modify environment variables in another process in Win32.

Enjoy!

Duoas 1,025 Postaholic Featured Poster

Macros aren't functions. When you use a macro the text of the macro is inserted verbatim into your code. Hence:

print macro str
.data
        x       db      str
.code
        mov     ax,     seg x
        ...

Gets used:

print "Hello"
print "world"

and becomes:

.data
        x       db      "Hello"
.code
        mov     ax,     seg x
        ...

.data
        x       db      "world"
.code
        mov     ax,     seg x
        ...

Which is the same as:

.data
        x       db      "Hello"
        x       db      "world"
.code
        ...

Why don't you just stick all your strings in the data segment with names to begin with? You can still use a macro:

.data
        str_hello db "Hello"
        str_world db "world"

.code
        print str_hello
Duoas 1,025 Postaholic Featured Poster
Duoas 1,025 Postaholic Featured Poster

vijayan121
> it would include input via menu, mouse, focus etc.
Please see the curses library to do those things.

WaltP
1. See the link I posted.
2. How many CLI systems do you know of these days that are in common use by the hoi polloi? Anyone writing secure systems or for something old or unusual won't post here asking how to clear the screen cross-platform.

Duoas 1,025 Postaholic Featured Poster

I'm looking your code over and I'm going to stop now. You need to get out a piece of paper and write down what your various registers values mean.

For example, you ask for an integer, get it and put it in $a0. Two lines later you completely clobber it with the address of the next message to print --you've lost the value you asked for!

MIPS processors have a ton of registers. Pick something that isn't likely to be used elsewhere, like $s0..$s7. When you need a temporary value, use $t0..$7. Only use $a0..$a3 when you need to (say, to read or print an integer).

Once you have your list, go through your code and make sure each register only has the value it is supposed to.

Booth's Algorithm has three values that are used: A, S, and P. You could say
A = $s0
S = $s1
P = $s2
Thereafter, $s0 should only contain the value appropriate to A. Etc.

Hope this helps.

[EDIT] Response to your last post. You can only print one at a time.

Duoas 1,025 Postaholic Featured Poster

I'll take a better look over all your code in a minute, but when you print you accidentally swapped your source and destination in the move command. move $v0, $a0 should be move $a0, {whatever register has the number to print} Hope this helps.

Duoas 1,025 Postaholic Featured Poster

http://www.catb.org/retro/

"Other" languages are those without a specific forum here at DaniWeb. For example, Perl has its forum, but Scheme does not. Scheme stuff goes here. Likewise, something like Tcl would go here.

Both these are powerful languages in their own right, and used often enough today. (They aren't dead or, even worse, the undead, like some of the stuff in the first link...)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Any time you find that you are repeating yourself, that is a good thing to turn into a loop.

First, figure out what changes each time and what stays the same. The thing that changes is a variable.
In your examples (done with [[I][/I]inlinecode[I][/I]] so that I can highlight something) they are all the same except for one thing: For x:= 1 to [B]1[/B] do Begin write('*') End; writeln; The only thing that changes each time is the number of times you go through the for loop. The first time it is 1, the second time it is 2, the third time it is 3, etc. Fortunately, you can use a for loop to count numbers 1, 2, 3, etc. (It is OK to have a loop inside another loop.)

That should be enough to help. Good luck.

Duoas 1,025 Postaholic Featured Poster

OK. A record is just a way to keep different kinds of data together.

Normally, you have simple types, like integer, char, real, etc.
You can have an array of things, but they are all the same kind (or type) of thing: array of integer, array of char, array of real.

Sometimes you need to store related things together. Say, a student. There's the student's name, current grade, etc.

type tStudent = record
                last_name:  shortstring;
                first_name: shortstring;
                grade:      integer
                end;

Now, if you want to store information about a student, you have all that stuff grouped together under one name:

var students: array[ 1..35 ] of tStudent;

You can access information about a particular student:

writeln(
  'Student 12: ',
  students[ 12 ].first_name,
  ' ',
  students[ 12 ].last_name,
  ' has a numeric grade of ',
  students[ 12 ].grade,
  '.'
  );

You can copy records just like simple data types.

var a_student, another_student: tStudent;
...
if a_student.grade <> another_student.grade
  then writeln( 'very possible...' );

a_student := another_student;

if a_student.grade <> another_student.grade
  then writeln( 'impossible!' );

You can use a with statement to get at all the elements of a record without having to repeat the record variable's name each time:

with a_student do
  begin
  first_name := 'Jenny';
  last_name  := 'O''Hara';
  grade      := 95
  end;
{ Now a_student is Jenny O'Hara, who has an A+ }

An enumeration (which you should have learned already also) is just a bunch of names. It is stored as a number, but we don't …

Duoas 1,025 Postaholic Featured Poster

C library functions (like printf) are typically prefixed with an underscore. In in the object library it is actually named _printf.

If you plan to use them you must also link the library itself. How to do this varies between assemblers / linkers.

Duoas 1,025 Postaholic Featured Poster

Back when people had to count nanoseconds on older processors it actually made a difference how you used certain registers.

Nowdays, just say MOV AL, 7 or MOV AX, 78Ah --whichever is needed.

Like Tight_Coder_Ex said, make sure you get a good reference. ROL, RCL, etc. are woefully underused opcodes, but very powerful. Look them up.

Follow along:

mov ax, 78Ah  ; AH == 07h, AL == 8Ah; AX == 078Ah
rol ax, 4     ; AH == 78h, AL == A0h; AX == 78A0h
rol ax, 4     ; AH == 8Ah, AL == 07h; AX == 8A07h

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

If you wish this to be "portable" across at least Windows and Unix, you should make use of the curses library. You can get PDCurses which works on both systems, and a few others to boot. Most *nix systems come with ncurses (or at least curses) already installed and usable. (Most basic curses functions are common to all three packages.)

Using curses allows you to directly control device input. You can test for input (whether there is any to read or not) and do fancy output, all using a library that is very portable.

Else:

To create a new thread in windows, all you really need is a function that will be called in the new thread. So your program will have a main() function, which gets executed when your program runs normally, and another function which is like main() but for that thread. You will also have to look up how to send signals between the threads, because you can't just modify common data without the possibility of corrupting it. The only exception would be if only one thread can write to a single-byte variable (such a boolean), and the other(s) may only read it. Not the best answer, but the simplest.

There is nothing wrong with using a system program to clear the screen. It is simple and you can count on "cls" or "clear" being present on most systems. The drawback is, of course, that it is a foreign program. See

Duoas 1,025 Postaholic Featured Poster

If you haven't studied records yet (sigh, halfway through the semester and your teacher's asleep), then just use an array of strings.

Take a single string like 5+(12*3) and convert it into an array of strings 5 , + , ( , 12 , * , 3 , ) The operator with highest precedence is (), so you find the sub-array containing the bracketed expression (elements 3..5) and evaluate it in recursion. Replace elements 2..6 with the result of the last evaluation, so you would have 5 , + , 36 .

The drawback is that you must check to see what kind of thing each element of the array is each time you look at it, and you must continually convert between numbers and strings.

I think you should go talk to your teacher and see if he can't give you a better idea of how he wants you to do this.

Your assignment got me interested so I did it myself in about 300 lines. About 100 of that is lots of error checking and extra functions I threw in (like a power function).

Duoas 1,025 Postaholic Featured Poster

Just as a random addendum. Above I said you could make your ADT as: (define (rank card) (car card)) That's fine, but if you really want to wow, forget the fluff and just say: (define rank car) Heh heh heh...

Duoas 1,025 Postaholic Featured Poster

> OK, so would eax, ax and al all be the same register/memory.
Yes and no. Read on.

> Can all three of those contain seperate values?
Yes and no. Read on.

AL is the low-order byte of AX. AH is the high-order byte of AX. Thus, AX is a 16-bit value (composed of two eight-bit values).

Likewise, AX is the low-order word of EAX. You can swap the low- and high-order words of EAX using the ROL opcode, say: ROL EAX, 16 .

So, if you set AL to 07h and AH to 8Ah, then it is the same as setting AX to 8A07h.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yeah, I just found it when reading here. I never knew you could do that before.

IMO, there is no reason to put labels on buttons except to get different fonts or font styles on a single button. My $0.02.

Duoas 1,025 Postaholic Featured Poster

You have no errors. However, I would be inclined to make a single enumeration type to tell me what the element is, as I suggested above.

Obviously, you can't just say readln( myEquation ); since the program has no idea how to read such a thing. You've already read a string that looks something like '1+20*3' .

After reading it, all you have to do is convert it into your array.

The first character is a digit, and there is only one of them. So I take the first character and convert it into a number: 1. The first element of my array is a number = 1.

The second character is a plus sign. So it is an operator. The second element of my array is a plus operator.

The third and fourth characters are digits, so I convert them into a number: 20. The third element of my array is a number = 20.

The fifth character is an operator, so the fourth element of my array is the multiplication operator.

Etc.

If you can think out the process like this, then you can also draw it on a piece of paper. Think about the kinds of information you must have to do it: indices into your string, an index into your array, a way to tell numbers and various operators apart, etc. This is the reason I suggested a record type: because it can have a value that tells you what kind of thing it …

Duoas 1,025 Postaholic Featured Poster

I've never programmed one myself, but your son could go through the TI-BASIC WikiBook. It has examples and explanations galore, all in tutorial format.

Good luck.

Duoas 1,025 Postaholic Featured Poster

An array is just a list of things all having the same type. An array of integer is: var a: array[ 1..100 ] of integer; (fixed-size array) var a: array of integer; (dynamic array)

Likewise, an array of char is: var str: array[ 1..100 ] of char; (fixed-size array)

So if your record's type is tElement you create an array as: var equation: array of tElement; (dynamic array)

You could have read this in your text book.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Just caught this...

Your documentation must be damaged. There is no error in what I have.
Where did you get your HLP files?

Like I said, mine are a bit old, but I can send it to you if you like.

Duoas 1,025 Postaholic Featured Poster

Have you looked at WikiPedia?

The next step is to get an assembler and start playing with it.

Duoas 1,025 Postaholic Featured Poster

A TButton was not designed as a container component, so the IDE won't let you put labels in buttons. Why not just change the button's caption?

If you must, however, see this thread.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

What do you think?

[EDIT] That is, use your own head.

Duoas 1,025 Postaholic Featured Poster

You have syntax problems.

line #16: get rid of the word "double" --you are not declaring a new variable (you've already declared "yards" above).

line #21: same kind of problem. Replace the word "double" with "meters".

Move your yards() function (lines 5..28) above main() (to line 8). Rename the yards() function to getyards().

You are missing a function named getmeters().

[EDIT] Also, you shouldn't be using &meters. And your second for loop is missing { and }.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Hmm, you know, you are absolutely right. I must have been really tired when I did that. Yes, leave the break statement out. (Or, leave it in and set i=-1 .)

Good job.

Duoas 1,025 Postaholic Featured Poster

So, according to your assignment description, you account for operator precedence by evaluating the same expression over and over until there is only a number (or error):

I start with 5 + 3 * 5 -2 The most precedent operator is *, so: 5 + 3 * 5 -2 5 + 15 -2 The remaining operators have equal precedence, so I'll just take them left to right: 5 + 15 -2 20 -2 and 20 -2 18 There are no more operators, so the answer is 18.

Now, you are supposed to store the expression in an array. So you could have an array of string, where each element is either a number or an operator: '5', '+', '3', '*', '5', '-', '2' Or you could have an array of some record type that tells you whether it is a number or an operator, say: type tType = (number, add, subtract, multiply, ...); type tElement = record element_type: tType; number: integer end; This is how I would do it (if forced to use an array), but if it is beyond you just stick to an array of strings. I assume the latter in what follows, but the concepts work either way.

So, even a bracketed expression is easily stuck in an array: 5 * (2 + (3 + 1)) becomes '5', '*', '(', '2', '+', '(', '3', '+', '1', ')', ')' This makes it easy to find operators. The brackets are special, in that they work on a sub-array. …

Duoas 1,025 Postaholic Featured Poster

Consult WikiPedia. It shows Booth's Algorithm in minute detail, and gives an example.

Your code should have several subroutines:
- one to display a binary number
- one to do Booth's algorithm and return the product

To display a binary number, just peel bits off of one end and put '0' or '1' into a character string as appropriate. Then print the string.

To input and output a decimal number, just use syscall. Here's a sample to get you started.

str_please_enter_int:	.asciiz "Please enter an integer: "
str_you_entered_int:	.asciiz "You entered: "

sys_print_int:		.word 1
sys_print_string:	.word 4
sys_read_int:		.word 5
sys_exit:		.word 10

i:			.word

main:	# ask for an integer
	lw  $2,  print_string
	la  $a0, str_please_enter_int
	syscall

	# get integer --> i
	lw  $2,  sys_read_int
	syscall
	la  $t0, i
	sw  $2,  ($t0)

	# Tell the user what the integer was
	lw  $2,  sys_print_string
	la  $a0, str_you_entered_int
	syscall

	lw  $a0, i
	syscall

	# All done
	lw  $2,  sys_exit
	syscall

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I cannot believe that your professor has given you an assembly assignment and not given you at least some of the target instruction set.

Here's an online PDF with the basic instruction set. It lists the opcodes for a variety of assemblers. Just scroll down for the MASM/TASM opcodes.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Pascal is pretty smart about typecasting between real and integer.

var
  i: integer;
  r: real;
begin
  write( 'Enter an integer> ' ); readln( i );
  write( 'Enter a float> ' ); readln( r );
  writeln( 'You entered ', i, ' and ', r:5:2, '.' );
  writeln( 'The sum is ', (i + r):5:2 )
end.

A good tutorial: Pascal Programming.

A good reference: Free Pascal Reference Guide.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

No one is going to give you code. Look in your textbook and at your class notes. There is an x86 opcode that does addition.

Duoas 1,025 Postaholic Featured Poster

>i mean is assembly have it own compiler .
Essentially, yes. An assembler turns assembly code into machine code.

>how can write assembly code .
What system are you using? There are many different assemblers...

Duoas 1,025 Postaholic Featured Poster

It works fine for me.

If you are using cin you should be aware that the standard input stream only ends when you press Ctrl-Z, ENTER on Windows or Ctrl-D on Linux.

Otherwise, you will have to get input as a string and convert it. (Sorry I was so slow on the uptake here...)

string userInputString;
int userInput;
...
if (!getline( cin, userInputString ) or userInputString.empty()) {
  cout << "NO INPUT\n";
  break;
  }
if (!(stringstream( userInputString ) >> userInput)) {
  cout << "NOT A NUMBER\n";
  break;
  }
if (userInput < 0) break;
...

Before you go sticking this in your code though, you ought to go talk to your professor and see what he really wants you to do.

Good luck.

Duoas 1,025 Postaholic Featured Poster

I think that is the part your professor is interested in.

A string is an array of characters. So, no matter how you get the equation (reading it from file or from user input) you still have a string: var equation_string = '1+2+3'; What procedures and functions and techniques have you learned that can index and split a string? Turn a character digit into an integer?

Duoas 1,025 Postaholic Featured Poster

The system() call forks out to another process. So if you use it to change the directory, it affects the new process, not your program.

Duoas 1,025 Postaholic Featured Poster

The best place to start is to get out a piece of paper and a pencil and figure out how you do it yourself. Once you know how to do it, step by step, you can tell the computer how to do it.

When you have thought it out enough to write some code, post it here and we'll be happy to help further.

Duoas 1,025 Postaholic Featured Poster

ExplainThat, this is a beginning programming school assignment. I really doubt the professor expects a recursive descent algorithm. Nor do I think he is permitted to redefine the shape of his input.

All the professor wants is some basic string parsing.

joygqy Show us some code, and we'll help you.

Duoas 1,025 Postaholic Featured Poster

Windows was designed as a 'do everything' GUI, so you automatically get things like GetFontMetrics().

X11 is an entirely different beast. I don't know of any standard libraries for stuff you want. If you are willing to use QT then I highly recommend it. It is a powerful system for this kind of stuff. I recommend you to the QT Online Reference Documentation. It is very complete and is chuck-full of examples.

Otherwise you are going to have to go pretty low-level.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

i take out break and i try your input the code is work and
when i leave it ,the code did not work ??????????

Yes, that's the whole point.

Get a piece of paper and a pencil and draw yourself what is happening when you use the code without the break statement, and you will see why it doesn't work.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Take lines 2..5 of my last post and stick them in front of line #37 you'll get what you want.

After doing that, you can delete line #15. You don't need to get min again after you have finished everything else. (Or are you just using this line to keep the console showing?)

Testing an istream for a boolean value returns whether or not you have reached EOF. So saying if (!cin) is the same as saying if (I_tried_to_read_past_the_EOF()) Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Hey there toolmanx, sorry to have responded so angrily. I was going to post and ask if you'd figure it out but I see you've marked it 'solved'.

C (and C++) is a weird and multi-headed beast. It is often easy to shoot yourself in places you didn't know you had --especially when looking through the MS documentation.

Since you were having trouble with pointers and structures, you might want to google "c pointers" and "c struct" for lots of good reading.

For C++, a couple of my favorite sites are:
C++ FAQ Lite
Incompatabilities Between ISO C and ISO C++
The second is useful if you really want to know how things work inside the language.

I hope I haven't driven you away from DaniWeb and you still feel you can post here for help.

Duoas 1,025 Postaholic Featured Poster

The ButtonClick event procedures only get called if the user clicks the button. So nothing will grey if the 'set disabled' code is in the button click procedure. The place to grey the button is in the load procedure: after loading the file, check to see how many items there are. If more than 10,000, then disable the appropriate buttons...

In Windows applications, things only occur when the user clicks something, or types something, or etc. The only exceptions are system events (which you don't need to worry about) and timer events (if you drop a TTimer on your form).

To set the application icon, go to project options --> Application. There should be a spot to set the program icon and the program title.

Duoas 1,025 Postaholic Featured Poster

Of course. You'll need to read up on recursion.

There is a basic principle: if you have a list (a b c d) (which, if you remember, is really: (a . (b . (c . (d . ())))) and if you can do something to the car of the list (or a ) and the cdr of the list (that is, the rest of the list: (b c d) ),
then you can do something to the whole list.

Remember, your list is a list of 'card's. So you'll have to use the card ADT to get the rank of each card and compare its value.

Hope this gets you started. Using scheme (and other functional languages) require you to think pretty hard.

Duoas 1,025 Postaholic Featured Poster

You are on the right track. The only problem is that char is a single character, not a whole list of them (or array of them). You probably want to use a pointer to an array of chars.

Also, don't use %s in scanf() without qualifying it with a maximum width.

char *getString(char *string);

int main() {
    char string[200];
    getString(string);
}

char *getString(char *string) {
    scanf("%200s",string);
    return string;
}

You can pass the length of the target string into the function if you want:

char *getString( char *string, int length ) {
  char format[ 30 ];
  sprintf( format, "%%%ds", length );
  scanf( format, string );
  return string;
  }

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

If you want to know, take out the break and try the following input:

Enter name,please: 0123 Enter the date 1 1 2007 Enter correct name of student, please 9jake

Also:

Enter name,please: no2 Enter the date 1 1 2007 Enter correct name of student, please m

The 10000 means to read a maximum of 10,000 characters. It is just some really big number that is sure to be larger than any line of text the user input after "2007" but before hitting ENTER.

Duoas 1,025 Postaholic Featured Poster

Since a "hand" object is a list of cards, and you want to get a list of cards from a hand, all you need to do is return the hand: (define (contents hand) hand) Now, if a "hand" object were something else, you'd need to do some work to turn it into a list...

Just wondering though, how can i seperate the two things in a card in a hand? would it be (suit (car hand)) etc?

Exactly. :)

Duoas 1,025 Postaholic Featured Poster
Duoas 1,025 Postaholic Featured Poster

Always fix errors in the order they come. Line 81 is incorrect, so no variable named recta is ever created, so when the compiler hits line 86 it complains about some structure variable you are using that doesn't exist.

Try this instead: Rect recta( 12.9, 13.4, 7.6 ); Also, please avoid MS stuff whenever possible. Your main function should be typed: int main( int argc, char *argv[] ) At the time MS wrote all those macros and junk, they had a pretty good reason. But there is no reason to contaminate new, unrelated code with it.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

That code won't help you with Pascal's Triangle.

The computer is too stupid to help you do something. First figure out how to do it yourself, preferably with pencil and paper. Once you can do that, telling the computer how to do it is relatively easy.

Duoas 1,025 Postaholic Featured Poster

Insomnia, alas.

It's alright, WaltP, I've been following his train of thought. He's confused about the functions of each method in his class and how the class relates to the file.

Since your assignment was due some 4 1/2 hours past, here's a more explicit answer. You need to think about why it works:

file vs string
A file is just a giant collection of bytes on disk, like an array. It can be interpreted all kinds of ways. One way is as a text file.
Here's a string (in C/C++): Now is the time for all good men\nto come to the aid of\ntheir country. You can see that the string would print on three different lines, as

Now is the time for all good men
to come to the aid of
their country.

So, what is special about one line or the other? Nothing, only that each line has a '\n' character between itself and any neighbors.

The very same holds true for text files. Both are essentially an array of characters (what we like to call a string in code), with '\n' peppered in for good measure.


the assignment
Your teacher specifically stated he wanted you to read the entire file all at once. That is, don't bother reading it line by line or character by character. Just get the whole string. Notice how we are no longer thinking about the text file in terms of lines, …

Duoas 1,025 Postaholic Featured Poster

You can get rid of the line Track(void); Move the following three lines: string title; string artist; float duration; to between the two lines: class Track { and public: Since duration is in seconds, it should probably be int, not float.

Make your time function match its prototype: void Track::time() In main(), declare your track array variable: Track TrackArray[ 5 ]; Get rid of: Track a; and make the next line read: TrackArray[i].createTrack(); Finally, when you call the time() method: TrackArray[1].time(); Your problems are mostly syntactical, but you should also read some more on creating and using classes. Try to find examples (there're tons on the internet).

Hope this helps.