Duoas 1,025 Postaholic Featured Poster

ShellExecute will always open the file with the associated program --in your case, with Notepad.

Take a look at CreateProcess instead. This will allow you to specify the program to run and pass as argument the name of the file to open.

I don't have the time at the moment, but if you are still struggling with it later I'll give you an example.

Duoas 1,025 Postaholic Featured Poster

Well, you can do that if you like, but you'd have to extract them before they could be used.

This is because WinHelp is a separate program which the application uses to display the help.

Duoas 1,025 Postaholic Featured Poster

It looks good as is to me.

However, you really should get rid of that <conio.h> stuff. It is not a good idea to mix C++ and C I/O. If you really must have a getch() type thing in there, use one of the C++ methods to do it.

best: cin.ignore( numeric_limits<streamsize>::max() ); also good: getline( cin, foostr ); cin.get( foochar ); Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Gnome shouldn't have any trouble executing py files by double-click.

1. Make sure you have the proper header in the file (as per my last post).

2. Failing that, make sure that python is installed with the proper MIME type. If not, you can do it yourself as per the documentation here.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Delphi provides you with the Microsoft Help Compiler (at least versions as old as D5 did), but using it directly is not fun.

You can google "help file creator" for the right stuff.

If you want to make HLP files, you can always check out Finn Christiansen's Shalom Help Maker, which is a nice, simple, 100% free tool. It looks like danish-shareware.dk is down right now... but you can google elsewhere.

If you want to make CHM files, I've never done that, so you'll have to sort through google yourself, alas.

Duoas 1,025 Postaholic Featured Poster

I suspect the problem is the same as I noted in your other thread.

If it is not, please also post the code where the exception is occurring, as I cannot debug code I've never seen (my mental powers are not yet that developed :twisted: )

Duoas 1,025 Postaholic Featured Poster

Yes, the debugger will catch those before the program does. Just click continue. If you run the program from the command prompt and not the IDE you won't see that message.

You can turn it off in the IDE if you go to Tools-->Debugger Options and uncheck "Integrated Debugging".

Duoas 1,025 Postaholic Featured Poster

He didn't ask about std, he asked about System.

Duoas 1,025 Postaholic Featured Poster

Lerner made a brilliant observation in noticing that the [] operator could be used to access data elements. See here for an example. And here. And here. You might want to change TheFilter's ShowValue and SetValue methods to use this subscript operator... (if you want).

I disagree that TheData and TheFilteredData should be separate classes (and I didn't get the impression that Lerner advocated it either...) simply because both hold the same kind of data: a list of values. Just because one has been transformed differently than the other doesn't change the specific characteristics of the data itself. No qualified professor will give you better marks for a poorly written program just to fit some perceived criterion. The best possible program best satisfies the program requirements. Make sense?

The constructor only needs to create and initialize the object so that it is usable in the sense that it can be handled without generating serious errors. That doesn't mean that it has to have all its data defined/allocated/whatever, or that it has to be of any actual use. You've thought about it correctly. Where, then, do you think is the best place to use new?

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Say nret = connect(sock, NULL, 0); C++ defines NULL as a pointer.

Duoas 1,025 Postaholic Featured Poster

I am presuming you are on Linux.

Try

#! /usr/bin/env python

print "Success!"

Hope this helps.

[EDIT] Oh wait. I just re-read your original post. You want to double click the python file? What window manager are you using?

Duoas 1,025 Postaholic Featured Poster

Your string needs to be pretty darn huge before you'll need to play with a progress bar.

So, first check the length of the string. If it is less than, say, 3000 characters, don't bother: just use the Replace function as you have it.

If it is larger, you'll need to
1. initialize the progress bar
2. search for the character to replace and replace it in a loop (that is, do it yourself!)
3. every time you have scanned over specific number of characters (say 1-2 thousand) update the progress bar, and defer to the window proc to process events for a moment.
4. finish.

You can stick your progress bar in a modal popup window (make sure it has a cancel button!) if you like. Display the window in step 1 and hide it in step 4.

Hope this makes sense.

Duoas 1,025 Postaholic Featured Poster

Google something like " 386 hardware interrupts " and just plain " hardware interrupts ".

Good luck.

Duoas 1,025 Postaholic Featured Poster

It looks like you are grappling with MS crap.

Make sure you compile with /clr command option.

Enjoy.

Duoas 1,025 Postaholic Featured Poster

It most certainly does exist, and vs2008 is pretty darn standards-compliant.

Be careful about your capitalization. Also, you must include one of the STL headers to see it.

Try:

#include <iostream>
using namespace std;

int main() {
  cout << "Hello world!" << endl;
  return EXIT_SUCCESS;
  }

However, you have changed the current scope by saying using namespace Email; You might want to try referring to it absolutely (not relatively): using namespace ::std; Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I'm not sure I understand your homework assignment.

You have three halt states: G (good), neutral, and B (bad).

However, your NFA only accepts for G and neutral. Hence, you really only have two halt states: G (good) and neutral.

This is all the information you have given me. With what you know (that I might not) about your NFA, can you prove that it is a regular language?

Hint: what is the definition/properties of a regular language, and what is the definition/properties of an NFA? (Or DFA, if you have already seen proof that a DFA and an NFA are equivalent).

Duoas 1,025 Postaholic Featured Poster

invisal
In C and C++ the single character '\n' is considered a 'newline' because it is automatically translated to the appropriate sequence when handling text files.

On DOS/Windows, the '\n' is translated to/from '\r\n'.
On a Mac, the '\n' is translated to/from '\r'.
On Unix, no translation is necessary.

The actual ASCII (and, hence, ISO/IEC 8859) meaning of '\r' is carriage return and the meaning of '\n' is line-feed.

Thus, if you were to configure your console output to binary mode, your test would work properly:

What follows is line feed:
                          _
[U]W[/U]hat follows is carriage return:

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

C++ is a little bit more strict about how it defines NULL than C. The compiler is complaining because you are passing a (void *)0 as the third argument, when it expects an (int)0.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

RajatC
Please take the time to look up information if you don't recognize something, rather than hijack someone's thread. string::npos is a STL object used to mean any index at or past the end of a string.

anallan
You actually have the right idea, but you made three (small) mistakes. The code in question is here:

for (int k = 0; k != j; k++){

          int i = firstStr.find(secondStr[k]);

          int gPos = i;

          if (gPos != string::npos){

                   while (gPos != string::npos){

                         newStr = firstStr.substr(0,i);

                         newStr += firstStr.substr (i + j);

                   }

          }else break;

    }

Your correct idea is to first find the index of the current second string character (you do this on line 3) and if the character is found in the first string (line 7) you want to erase it.

Your second correct idea is that you don't want to move on to the next character in the second string until you have eradicated all occurrences of the current second string character out of the first string.

Your first mistake is the position of the loop (line 9). Currently, gpos will never change. Every time you loop you need to update gpos just like you did on lines 3 and 5. (It will be easier if you get rid of the variable i and just use gpos.)

The second mistake is how you attempt to get rid of the found character in the first string (lines 11 and 13). WaltP correctly …

Duoas 1,025 Postaholic Featured Poster

If you have two points:
(10, -7)
(3, 12)
then how do you find the distances between them?

The distances are:
- distance between the x values (what you are looking for)
- distance between the y values (or "height")
- distance between the two points (the length of the line connecting the two points)

Surely you've done this in math class?

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Please learn to use code tags. I've already given you a number of examples.

In general, the rule is that you must verify user input at every step. Generally with user input this means to always accept strings. This also requires a little ingenuity when deciding how to validate the input.

In the following example, I have chosen an interactive program. It will complain until you give it valid input.

{$apptype console}
uses SysUtils;

var
  // Here's the stuff we want
  name: string;
  ident: integer;

  // Here's stuff we need to validate user's input
  userinput: string;
  num_digits_and_punct, cntr: integer;

begin
  // Get the user's name.
  //
  // The user could enter anything, even a number.
  // Some people actually have digits in their name,
  // so it is not really feasible to say "that's not a name",
  // excepting for one case: most principalities do not
  // permit a person's name to be just a number or
  // punctuation (that is, it can't be composed only of
  // digits and/or punctuation).
  repeat
    write( 'What is your name? ' );
    readln( name );

    // Convert all tabs, whitespace, ctrl chars, etc. to spaces
    for cntr := 0 to 31 do
      name := StringReplace( name, chr( cntr ), ' ', [rfReplaceAll] );
    name := StringReplace( name, #127, ' ', [rfReplaceAll] );

    // Get rid of leading/trailing spaces
    name := trim( name );

    // Get rid of excessive internal space
    while pos( '  ', name ) <> 0 do 
      name := …
Duoas 1,025 Postaholic Featured Poster

The easiest way to compare two strings depends entirely upon your assembler.

Chances are though that you might do just as well to write it yourself. First you need to have a good 80x86 assembly opcode reference. Here's a good one I found on Google.

I recommend you check out the repe cmpsb string command. It is used to compare two strings for equality.

Also, listen to Ancient Dragon. He knows what he is talking about. Unless you know exactly what tricky stuff to do, you must do it as he suggested: read the source file while writing a new file. Once done, you can delete the source file and rename the new file to have the same name that the source file did, if you want.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Altzaportu
Your program works fine for me. Here's some test inputs I used:

D:\prog\d\foo\dt\altzaportu>Project23.exe
Please enter the date as d-m-y: foo You did not enter a date like I asked you...

D:\prog\d\foo\dt\altzaportu>Project23.exe
Please enter the date as d-m-y: 1 jan 2008 You did not enter a date like I asked you...

D:\prog\d\foo\dt\altzaportu>Project23.exe
Please enter the date as d-m-y: 1-jan-2008 You did not enter a date like I asked you...

D:\prog\d\foo\dt\altzaportu>Project23.exe
Please enter the date as d-m-y: 1-1-2008 D:\prog\d\foo\dt\altzaportu>Project23.exe
Please enter the date as d-m-y: 1-1-2007 Too many days!
Please enter the date as d-m-y: 1-1-2008

What do you mean by "It gives Error"? Please post some output.

BTW, your program does have a bug: What happens if you enter a date that is exactly 90 days different than today's date?


Micheus
Yoinks. I didn't expect you to start looking around for some instance where you got my name wrong (I didn't think you had...). It's just that it has so many vowels in it people wind-up typing "Duos" and the like.

The name is actually Dúthomhas, but no one (except Irish folk) could hope to pronounce that right...

So actually I was complimenting you on your keen observations... :$

Duoas 1,025 Postaholic Featured Poster

I always tend to stick the main program one directory above all the other modules. My directory tree will look something like this:

Gork/
  gork.py
  README
  ...
  images/
    title.tga
    player1.tga
    player2.tga
    ...
  modules/
    __init__.py
    gameboard.py
    globals.py
    tga32.py
    widgets.py
    ...

And so on. Obviously, "gameboard.py", etc. are the modules. I've wrapped them in a subdirectory-module. To use them, I import them in gork.py thus:

from modules.globals import *
import modules.widgets
...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Unfortunately, the "Julian Day Number" is one of those terms I mentioned (or rather, it is often abused to mean "the day of the year").

Fortunately it looks like that link uses the JDN correctly! Nice catch!

Duoas 1,025 Postaholic Featured Poster

It is a standard POSIX function. It is not a standard C/C++ function.

See Wikipedia for more. Be sure to click on the first few links down at the bottom in the "See Also" section too.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Thanks!

As always, readers should do as Micheus did and immediately refer themselves to the Delphi documentation. Even if you, like he, already know quite a lot about handling dates in Delphi. There is a lot of useful stuff in there.

Also, the unit(s) you need to put in your uses clause vary between Delphi versions. The DateUtils unit was introduced in Delphi 6. FPC uses DateUtils also. For Delphi 5 and earlier all the date stuff is in the System unit.


BTW, Micheus, thanks for that nifty function! That floating point error there is not Delphi's fault though... that is a problem common to all digital computers. The way you handled it is brilliant and instructive!


Finally, I would like to add some thoughts to reading time/date information from a string. If you know your input will take one of several distinct forms, you can use try..except blocks until you get a correct date. For example:

function read_date_format_1( s: string ): tDateTime;
  begin
  // this function tries to read dates formatted as '2007-12-31'
  end;

function read_date_format_2( s: string ): tDateTime;
  begin
  // this function tries to read dates formatted as '2007 12 31'
  end;

function read_date_format_3( s: string ): tDateTime;
  begin
  // this function tries to read dates formatted as '31/12/2007'
  end;

function read_date( users_input: string ): tDateTime;
  begin
    try
      result := read_date_format_1( users_input )
    except on EConvertError do
      try
        result := read_date_format_2( users_input )
      except on EConvertError do
        result := …
Duoas 1,025 Postaholic Featured Poster

It works for me (using MASM). Of course, I wrapped it up appropriately in the necessary directives and added code to display a better message and to terminate the program.

.model small
.stack 64

.data
str_current_drive_is db 'The current drive is $'

.code

start:	mov ax, @data
	mov ds, ax

	; print "The current drive is " to standard output
	lea dx, str_current_drive_is
	mov ah, 09h
	int 21h

	; get the drive number in AL (0, 1, 2, ...)
	mov ah, 19h
	int 21h

	; convert the number to a letter ('A', 'B', 'C', ...)
	add al, 'A'

	; print the drive letter to standard output
	mov dl, al
	mov ah, 02h
	int 21h

	; exit 0 (success)
	mov ax, 4C00h
	int 21h

end start

How do you mean, "nothing happens"? You aren't seeing any output? Or the program won't run?

Your last question is answered in the comments with the code.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You want the user to be able to buy items. (You accidentally misspelled that.)

Your best bet is to use one of the STL collection classes with a base item type.

That is, create an abstract class for your items, and derive specific items from it. Then use something like std::set to store the items.

Hope this helps. If you get stuck post again.

Duoas 1,025 Postaholic Featured Poster

Whenever programming in assembly you should have at least one very good resource for documentation. Google helps too.

Some common INT 21h documentation.

The documentation indicates that function 19h returns the drive number in AL as an integer. You can print it after converting it to an ASCII character.

; get the drive number in AL (0, 1, 2, ...)
        mov ah, 19h
        int 21h

        ; convert the number to a letter ('A', 'B', 'C', ...)
        add al, 'A'

        ; print the character to standard output
        mov dl, al
        mov ah, 02h
        int 21h

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The question frequently comes up on how to manipulate dates and time using Delphi.

Delphi 2.0 and later supply the TDateTime format, which is actually a floating point number (stored as a IEEE double) containing the number of days that have passed since 12 December 1899.

(Delphi 1.0 calculated the date from the year 1, so to convert a Delphi 1.0 date to a Delphi 2.0 date, use date_d2 := date_d1 -693594.0; The date format was changed to be compatible with OLE 2.0 Automation.)

So, to get the current date and time, use one of the following functions:

var
  the_date,
  the_time,
  the_day_and_time: tDateTime;
begin
  the_date := date;
  the_time := time;
  the_day_and_time := now;  // same as the_date + the_time
end;

You can add or subtract days from the date.

var
  one_week_from_tomorrow: tDateTime;
begin
  // (tomorrow is 1 day) plus (one week is 7 days)
  one_week_from_tomorrow := date + 8.0;
end;

You can add or subtract months with the IncMonth function:

var two_months_ago: tDateTime;
begin
  two_months_ago := IncMonth( now, -2 )
end;

To add or subtract weeks or years, first calculate the correct number of days. That isn't always too easy. See "Getting and Setting the hour..." below for ways to access individual parts of a date, and an example.


TTimeStamp
Sometimes you want just a little more accuracy when dealing with time than a fractional part of a day. For that you will need to use the TTimeStamp type, which is a record defined …

Duoas 1,025 Postaholic Featured Poster

Each time you divide you loose the least-significant digit (the one in the ones position).

So if you want to get the tens position digit (2 in both our examples) you divide by 10 to move it to the ones position. Then use modulo 10 to extract the ones digit only.

This is pure math, so you'll have to think about it some. Good luck.

Duoas 1,025 Postaholic Featured Poster

To be honest, I didn't want to look too hard at this (and I haven't) just because you didn't put your code in the proper tags.

[[I][/I]code=Delphi[I][/I]]
program hello;
begin
writeln( 'Hello, world!' )
end.
[[I][/I]/code[I][/I]]

becomes all nice and pretty, easy to read, and easy to select, copy, and paste for testing:

program hello;
begin
  writeln( 'Hello, world!' )
end.

BTW, you don't actually have to explicitly assign '' or 0 or nil to anything in the constructor. The inherited; does that for you.

At just a quick glance, it looks like you are trying to keep track of the objects with a counter. So when you say AddObject the first time it goes something like this:

  1. AddObject( 1 )
  2. setLength( Objects, 1 )
  3. Objects[ 1 ].create

You are getting a memory fault because Objects[1] doesn't exist. Objects[0] does though...

The other problem is in part 3 there. You cannot just say foo.create You must say foo := TFoo.create (that, or you must first use the new procedure...).

In general, the way you should handle this kind of thing (playing with dynamic arrays) is always to refer directly to the dynamic array for information about itself. You can do it thus:

procedure TChunk.AddObject;
  begin
  setLength( Objects, length( Objects ) +1 );
  Objects[ high( Objects ) ] := T3DObject.create
  end;

This code also has the property that it will generate a proper exception on error.

If ever …

Duoas 1,025 Postaholic Featured Poster

AdAware is a good program. Also, you should be running a good anti-virus, which will also watch for and eliminate adware. I got the impression that you tried these already?

The only other solution is to locate and purge affected software. Perhaps a backup of all your data files and re-install Windows as a last resort. Then scan your backed-up files with a good virus/adware filter.

Duoas 1,025 Postaholic Featured Poster

Just to be explicit: that should fix your popup problem, but it may cause other problems with legitimate use.

The best bet is to get rid of the adware. It is possible that the adware has infested IE.

Duoas 1,025 Postaholic Featured Poster

Replace iexplore.exe with a program that does nothing:

1. rename iexplore.exe to ie.exe or some such.
2. compile a program that does nothing and name it iexplore.exe.


I believe that you'll have to do this in safe mode or some such, and you may have to dink with other system backup files also. There is a utility called "replacer" you can google that is designed to help you do this.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Are you saying that you have Mozilla as your default browser but specific web pages load IE to display popups?

That's disturbing. Go to Bugzilla and post links to the pages that are doing that.

Duoas 1,025 Postaholic Featured Poster

Python deals only with the Gregorian calendar. Certain terms (like "Julian") can be properly applied to specific things withing the Gregorian system, but the Julian calendar it is not.

Usually the Proleptic Gregorian calendar serves well enough for modern computing tasks...

Try googling "gregorian julian" for conversion algorithms. Good luck.

Duoas 1,025 Postaholic Featured Poster

> By "shifting" I meant knocking off the least significant digit...
Yeah, I figured that's what you meant, but a total newbie would have confused it. Natural language is an enemy, alas. (I know it; I confuse people often enough when I try to make a short answer. And no one reads a long answer through...) :sweat: ;)

Duoas 1,025 Postaholic Featured Poster

Shifting only works for powers of two. In any case, it is a substitute for what is actually happening: you are dividing by the radix.

So, to get the tens place from a decimal number, you must first divide by ten, then get the remainder of another division by ten. For example:

4321
4321 divide 10 --> 432
432 modulo 10 --> 2

To get the hundreds place, you divide by ten twice (which is the same as dividing by 100). Etc.

Typical integer to string conversion routines use exactly this algorithm to get each digit, repeating until the number is zero.


It will be the same no matter how many bytes you use, since base 10 doesn't directly map to base 2; that is, a base 10 digit may span from one byte to another.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Agreed, but when dealing with new programmers I have learned by experience (teaching and tutoring) that debugging works best once a firm concept of what should be happing is established. Anyway...

iamthwee commented: Well said +13
Duoas 1,025 Postaholic Featured Poster

You can't do that without very carefully doing some really bad things first.

Even in the same program, each loop is a separate entity. There is no reason why a loop in one program file should affect a loop in another.

If A eventually stops, then it will stop, no matter what B does.
If B never stops, it will never stop, no matter what A does.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I always take it a step farther and just tell people to forget the code. Get out the paper and crayons first, draw what must happen, then write the code to do exactly that.

Disentangling new programmers from bad code is more difficult and confusing than just going through the steps of writing the code correctly to begin with...

Duoas 1,025 Postaholic Featured Poster

The Pos and AnsiPos functions require string arguments. Not char. Make sure you are using strings.

Duoas 1,025 Postaholic Featured Poster

Alas, it looks like I was mistaken about python... None of the python interfaces to CreateProcess report back changes to the enviornment dictionary...

It looks like printing to stdout and using one of the popen module's functions is your best bet...

Duoas 1,025 Postaholic Featured Poster

I haven't used python to do this, but in Windows it is possible to specify the environment table the child is to use. Thus, if the child modifies its environment, it is modifying something that the parent has direct access to.

Unless someone beats me to it, let me see if I can find how to create a process this way in python. This will, of course, be a windows-specific thing to do...

Duoas 1,025 Postaholic Featured Poster

Before you read that link, you should be aware that if you are doing this for an algorithms class the professor expects you to figure this out on your own. It's not that hard. Oh, and he will know if you use one of the algorithms found through that link. (Honestly. Professors can spot that from miles away.)

bugmenot, I'm going to bug you: posting a link to someone else's answer is the same as just giving him the answer yourself. Please don't.

mir12
You'll have to consider several things:

  1. How is the graph stored? Does it permit loops? Is the graph directed or not? etc.
  2. How do I convert user input into the graph? (What names are the user allowed to use for the nodes? How do I know how many nodes are in the graph when the user is finished with input? What happens if the user enters the same edge twice but with different weights? etc.)

Hint: The way you store the graph will help you solve the problem. What data structure have you studied so far that best represents a graph?

Hint: Use recursion to traverse the graph.

Hope this helps. Let us know if you get stuck.

Duoas 1,025 Postaholic Featured Poster

I think you are out of luck. See here.

Duoas 1,025 Postaholic Featured Poster

The problem is you aren't thinking it through: you are trying to use things before they exist.

To best help, you need to work on how to convert abstract stuff like "draw a door of a specific width" to the code that actually draws a door.

Do like I suggested in first thread woooee linked, and think about exactly what information
1. that you have
2. that you must calculate
in order to draw each part of the house.

Also, always get only the minimum amount of information you need from the user before drawing each part of the house. Again, read the link woooee listed.

You'll have to think about this a bit more, alas. Good luck.

Duoas 1,025 Postaholic Featured Poster

Since you are using C, your file should be named "calculator.c", not "calculator.cpp".

The problem is that you haven't paid any attention to operator precedence. Line 37 tests all the operators as if they had the same precedence.

The whole point of RPN is that it makes precedence moot -- that is, operators are applied as they appear. In standard notation, however, it makes a great deal of difference.

You are not saving yourself any trouble to convert to RPN. You will still have to code against precedence properly when lexing the standard math program.

So your choices are:
1. Always use parentheses in the standard formulations
2. Write something that handles precedence (in which case you might as well forget the RPN stuff and just calculate the answer as you go). I recommend you google through "recursive descent" a little. This will be a bit of a learning curve. The wikipedia has some stuff which would be a good starting point for you.

Good luck.