Duoas 1,025 Postaholic Featured Poster

It's probably in your while (status != EOF || status2 != EOF) statement.

That || should be an && .

Oh yeah, don't int main(void) .
Always use either:
1. int main() 2. int main( int argc, char *argv[] ) Main takes arguments. If you want to ignore them, use form 1 (which says to the compiler: "I don't care about any arguments this function takes.")

Jishnu
"a.out" is the default executable name that compilers produce on *nix systems. On Windows you compile "foo.c" and get "foo.exe". On Unix you compile and get "a.out".

Duoas 1,025 Postaholic Featured Poster

In the DPR file before the main form is created, set the monitor to the one you want: application.mainForm.monitor := screen.monitors[ 1 ]; I've never done this before, nor have I ever had a dual-monitor system, so I can't say this will actually work... But I think it will.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Try Google.

The first link looks to have promising information.

Also, even though you aren't writing a game, this kind of question might be better answered in the Game Development forum.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The compiler is mangling your function name to "C" standards. It is looking for "_hhPostMessageA" instead of "hhPostMessageA" (note the underscore).

What you are doing is fairly compiler-specific, but these days a lot of them accept the __declspec keyword. extern "C" __declspec( dllimport ) void hhPostMessageA( HWND, UINT, WPARAM, LPARAM ); (I've not done this in C++ before, so this example might not be quite right. But even if it is, it might not be quite right for your compiler.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Or you could just turn off the skipws flag: while (input >> noskipws >> next)

Duoas 1,025 Postaholic Featured Poster

I'll get it to you shortly. I was in the middle of dinking with some stuff in it when I left-off and left it a mess. Once I've cleaned it up better (I should be done by tomorrow) I'll send it to you.

I'm not doing anything more to the syntax highlighter for the moment, and I discourage you using it for any serious stuff (as it is currently broken and slow), but everything else should work fine. (System Tray icon stuff, pop up menus, non-rectangular windows and pop up balloons, application mutex, and a few super-useful utilities I wrote years ago and never stopped using.)

Give me a day...

squidd commented: it wasnt mentioned here what was sent to me, thus the reputation point looks unwarranted, but I assure you it is! +1
Duoas 1,025 Postaholic Featured Poster

How about you first make an effort to solve your problem with the suggestions I gave you? If you do the exercise I suggested and work in the order I suggested then you'll learn something useful instead of my simply giving you code. At the very least you'll be able to pass your exams.

Duoas 1,025 Postaholic Featured Poster

This is where it is time to get out the construction paper and crayons. You need to draw yourself adding nodes to a linked list. Be sure to draw lots of little arrows: one from each pointer to the node it references.

There is the node type itself (which you defined), containing a "next" pointer (which you also did a good job of defining)

Then there is a "head" or "first" pointer, say: var my_equation: pEquation = nil; The head pointer always points to the first node in the list. You can then write procedures and functions (which take this pointer as argument) to add, remove, move, find, count, etc. specific nodes in the list. Routines that modify the list should be functions that return the new head node, or should take the head node as a var parameter (that is, as a reference parameter) so it can be modified directly --(just in case it changes).

Good luck.

Duoas 1,025 Postaholic Featured Poster

I didn't think anyone was still looking at this problem. I'll pack up my example code for you. (It isn't finished as far as syntax highlighting is concerned, but it does everything with the system tray that you are trying to do. I'll PM it a little later today.

For the background image, there are two ways I can think to do it.
1. Put your image component on the form, and before saving and compiling your project make sure it is at the bottom of the Z-order with all the other components on the form.

2. (More robust). Overwrite the Paint method of the form. The docs should have an example of this...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Please use code tags.

Think about why that messes up and you'll be able to fix it easily. You are on the right track.

Also, there is a special case for the very first line.

Duoas 1,025 Postaholic Featured Poster

As long as you don't examine sub-nodes more than once, yes.

Duoas 1,025 Postaholic Featured Poster

Besides the obvious solution[EDIT]s[/EDIT] I gave you, I don't see any way to do it without playing with the preprocessor (which, to my mind, is actually messing with more than one character...)

Well, my blinders are intact...

Duoas 1,025 Postaholic Featured Poster

Think of it recursively.

Duoas 1,025 Postaholic Featured Poster

You need to count how many lines there are.

Every time you read '\n' from the file, increment your current line number and print it to the file.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

There's a limit to how big your data structures can be.

Since MAX is 10,000 you are asking for an array of
10,000 x 10,000 x sizeof( int ) bytes
which is likely about 400,000,000 bytes, which is nearly a half a Gigabyte!

Either make a smaller array, or google "sparse arrays" and "sparse matrices" and "hash tables".

Good luck.

Duoas 1,025 Postaholic Featured Poster

They are not expected to. They are supposed to be used to pass arguments to subroutines: argument0, argument1, etc.

If you need to preserve it across the call to a subroutine, push it on the stack and pop it once the subroutine returns.

# preserve my $a1 before calling the subroutine
sub $sp, $sp, 4
sw $a1, 4($sp)

# do whatever is necessary to call the subroutine here
...
jal a_subroutine

# restore my $a1
lw $a1, 4($sp)
add $sp, $sp, 4

If you read up on "stack frames" you can just preserve some space on the stack when your routine starts and then use the appropriate index when necessary:

my_routine: sub $sp, $sp, 4+8  # $ra + two local vars
            sw $ra, 12($sp)

            ...

            # preserve $a1 and $t0 (my local vars)
            sw $a1, 8($sp)
            sw $t0, 4($sp)

            # do whatever is necessary to call the subroutine here
            ...
            jal a_subroutine

            # restore $a1 and $t0 (my local vars)
            lw $a1, 8($sp)
            lw $t0, 4($sp)

            ...

            # return to caller
            lw $ra, 12($sp)
            add $sp, $sp, 4+8
            jr $ra

Hope this helps.

[EDIT] bStiffler582 Please don't just give people code. Also, he's doing the Binary GCD, not the Euclidean.

Duoas 1,025 Postaholic Featured Poster

You are having problems dealing with pointers.

I know this sounds stupid, but you need to get out a piece of paper and draw yourself a linked list, with little arrows pointing from element to element.

Something else that might help you is to use references instead of pointers when you can. void Insert( Productptr &head, ProductNode p ) Call it with: Insert( PhoneList, p ); And inside use it normally: if (head == NULL) head = newNode etc.

Yes, a reference is really a pointer under the covers, but if you use it you won't have to worry about two levels of indirection (which is what is causing you to mess up in Delete()).


Secondly, you are using cin >> to get strings from the user. Some professors continue to teach that but it is wrong (because at some point the user will have a space in his input --particularly for something like "description"). Also, your strings are char arrays. What happens if the user inputs a code longer than 4 characters? Or less? How will you know? How will you keep it from messing up the input for description?

The most robust fix is to use a std::string for all user input. Say:

#include <sstream>
...

// The temp string to use for all our input
string s;

...

// Get the 4-digit code
cout << "Item code : ";
getline( cin, s );
// Validate it
if ((s.length() <
Duoas 1,025 Postaholic Featured Poster

I think the OP is trying to do something that is way over his head right now.

HTML is a markup language. Your web browser or IDE (or both) must know how to read and display it to use it.

It also sounds to me like you are trying to do something fancy with the development environment, which has nothing to do with the language itself but rather to do with modifying the tools that edit and/or display the markup.

For a beginning project you've skipped the ground floor and taken the elevator straight to the 80th...

Duoas 1,025 Postaholic Featured Poster

It looks like you are trying to dereference a NULL pointer.

Duoas 1,025 Postaholic Featured Poster

Are you talking about Delphi's ShortDateFormat /ShortTimeFormat /LongDateFormat /LongTimeFormat variables (in SysUtils)?

Or are you talking about changing something in the OS?

Duoas 1,025 Postaholic Featured Poster

The SetLength should not be in the loop, but after it. Other than that it looks fine to me.

BTW. You should be able to replace lines 27..29 with just records[j] := records[j+1]; Don't know why you are using all-caps keywords, but it sure is anachronistic (a hold-over from brain-damaged BASIC users). I've not changed the functionality of your code here. Just structured it a little better...

PROCEDURE delete(VAR records: employeeRecords);
VAR
  n, j: Integer;
  nameDel: String;

BEGIN
  Write('Name: ');
  Readln(nameDel);

  n := 0;

  WHILE (records[n].name <> nameDel) AND (n < High(records)) DO
    Inc(n);
 
  IF records[n].name = nameDel
    THEN BEGIN
           FOR j := n TO High(records)-1 DO
             records[j] := records[j+1];
           SetLength(records, High(records))
         END
    ELSE BEGIN
           Writeln('That employee could not be found!');
           Writeln
         END
END;

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Please stop bumping ancient threads.

No one is going to do your homework for you. You'll have to learn it yourself.
Here is a good place to start.

The very first example is hello world.

Duoas 1,025 Postaholic Featured Poster

Er, yeah. It's one of those naming things.

A virtual partition is so called because it doesn't necessarily correspond to physical structures. It's not hidden though. [EDIT] but I think it can be... [/EDIT]

Duoas 1,025 Postaholic Featured Poster

I've never heard of an INI file that isn't ASCII encoded. Too bad they don't all just die... (that is, seems odd to me people still use them, because for all their supposed simplicity they can sure give you headaches)...

Alas.

Duoas 1,025 Postaholic Featured Poster

It is easy enough to write something that works with std::string.

std::string GetFileTitle( std::string filename ) {
  std::string result;
  short len = GetFileTitle( filename.c_str(), NULL, 0 );
  if (len < 0) throw 1;
  result.resize( len -1, '\0' );
  if (!GetFileTitle(
    filename.c_str(),
    const_cast<char *>( result.c_str() ),
    len
    ))
    throw 1;
  return result;
  }

There are several ways to deal with errors. In this example I just throw an int exception. You may want to adjust it to throw something else or return an empty string or whatever strikes your fancy.

Enjoy.

[EDIT] Oh yeah, an example of use: string FullPath = "c:\fooey\quux.txt"; string filename = GetFileTitle( FullPath );

Duoas 1,025 Postaholic Featured Poster

I've had my bad moments too. I'm fairly new myself, and on my second or third post I managed to offend several people who disagreed with me about something...

Alas.
:-/ :)

Duoas 1,025 Postaholic Featured Poster

Ah, yes.

The thing to remember is that in C++ there are two parts to everything: the definition of a thing's type and the declaration of a thing itself.

The type of a thing is an abstract concept. As such, it compiles to zero bytes worth of executable code. (Discounting RTTI info and the like, which is something different.) A thing itself, though, is entirely different. It occupies space. So, you can't have an integer, but you can have a specific integer value, like 2 or -7.

Include files are fluff. They don't compile to anything. What they do is inform the compiler about data stored somewhere else. Typically, this is information about the types of things, and fairly often (as in the case with the extern value) information about a specific thing stored elsewhere.

So, main.cpp does actually have the "drawscr.h" header inserted directly in the file (well, maybe not, but that's another issue. For all intents and purposes it is just inserted). All the header should do is tell main.cpp about stuff that exists elsewhere (specifically, in drawscr.cpp, about which main.cpp knows nothing).

So, when main.cpp gets compiled with, say, c++ -c main.cpp you get an object file that contains all the actual things that main.cpp defines. Main.cpp doesn't define message, but it knows about it and can use it, because the drawscr.h include file told the compiler that message exists somewhere else.

Likewise, when drawscr.cpp gets compiled c++ -c drawscr.cpp you …

Duoas 1,025 Postaholic Featured Poster

Not that I know of, but you could probably roll your own pretty easily. I know there are a lot of libraries people wrote on Google as well...

How complex is the INI file you want to read? (Does it stick to the simple [this is a section header] this=is a value format?)

I'm sure I came across a nice library about a year ago that is pretty advanced. If I can remember what it is I'll post back.

jaepi commented: Can foretell posibilities. Tsk tsk +2
Duoas 1,025 Postaholic Featured Poster

Here's some desperate help:

If I understand your problem correctly, you must get two numbers from the user, x1 and x2, then make an array (or vector) of values from x1 to x2 inclusive?

PCSpim is neither a compiler nor a proper assembler. It is a simulator for a virtual machine.

Write your tal program using your favorite plain-text editor (like emacs or notepad or whatever), load it into spim, and run it with the "Go" button. The only caveat to using Spim is that your program must begin with the label "main" instead of "__start".

Try typing in some simple examples from your textbook. Then try creating some simple examples of your own design.

Here's a simple example designed to help you in your project:

# Example program to print a friendly
# message five times, then quit.


.data

# This is static data.
# Its size does not change.

# This is the string to print
str_hello:	.asciiz "Hello world!\n"

# These are syscall argument values
# (I like to name them for easy use)
print_string:	.word 4   # $a0 : address of string to print
exit:		.word 10


.text

		# print_n_times( str_hello, 5 )
main:		la	$a0, str_hello
		li	$a1, 5
		jal	print_n_times

		# quit
		lw	$2, exit
		syscall

# subroutine
# arguments:
#   $a0 : address of string to print
#   $a1 : number of times to print it
#
		# preserve return address on stack
print_n_times:	sub	$sp, 4
		sw …
Duoas 1,025 Postaholic Featured Poster

I'm sorry you took my response that way, but you are the one being arrogantly rude.

Since you are new to the forum you might want to take some time to read the Forum Announcements.

Those of us who like to take the time to help people here don't like it when some newbie shows up and in his second post starts doing things universally considered obnoxious. Please take the kind hint.

Had Narue or WaltP or Salem or someone else like them (who are all very knowledgeable and very helpful) responded, you might have gotten a much less friendly response --as they have dealt with a lot more snot than I have, and have a much lower tolerance for it.

If you plan to behave and be nice, welcome. Remember, words online are easily misinterpreted whereas in direct conversation they wouldn't be. Don't assume the worst.

Also, don't assume the OP and Narue are blindingly stupid. They were both well beyond including <windows.h> and linking errors. The question was answered.

I give you this by way of welcome and advice. Take it as you will.

Duoas 1,025 Postaholic Featured Poster

I know this is probably daft, but wasn't I including the same header file multiple times in drawScr.cpp and main.cpp?

No.

The file "drawscr.cpp" includes three files: iostream, string, and drawstr.h. Each file is included but once.

Likewise, the file "main.cpp" includes three files: iostream, string, and drawstr.h. Again, each file is included but once.

"drawscr.cpp" gets compiled to "drawscr.o". And "main.cpp" gets compiled to "main.o". Then the linker puts them together into "a.exe" or "a.out" or whatever.

BTW. In "drawscr.h" you use std::string but never actually include <string>. What if the user (that is, the programmer using your code) didn't include <string> before including "drawscr.h"?

In a like vein, included files should never have using statements in them.

In both these cases, you can get away with it because it is a small project you are working on by yourself, but when things get larger and when other people become involved, invariably you'll wind up breaking someone's (reasonable) assumptions on what is what.

The only difference between daft and obvious is knowledge. Hope you feel less daft now... (and don't put yourself down).

:)

Duoas 1,025 Postaholic Featured Poster

The #include "filename" directive effectively works by directly inserting the named file into the text.

// z.h
int i;
// z.cpp
#include "z.h"
// main.cpp
#include "z.h"

int main() {
  i = 42;
  return 0;
  }

Is the same as:

// z.cpp
int i;
// main.cpp
int i;

int main() {
  i = 42;
  return 0;
  }

So you have, in fact, declared the variable twice.

To get around that, declare it as extern.

// z.h

// declare the variable to exist, but don't cause it to exist
extern int i;
// z.cpp
#include "z.h"  // the variable is only declared as existing

// cause the variable to exist
int i;
// main.cpp
#include "z.h"  // the variable is declared as existing

int main() {
  // the variable is usable here, since main.ccp knows it exists...
  i = 42;
  return 0;
  }

Your code has one other problem. message is declared as a pointer to a thing, but no instance of that thing actually exists. You must either malloc() or statically declare the thing before using it.

Using malloc()

void initMsg() {
  message = malloc( sizeof( MsgStock ) );
  ...

Statically declaring it:

MsgStock _message;  // static variable

void initMsg() {
  message = &_message;  // now 'message' points to something
  ...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I've never needed to play with wav files myself, so I know nothing about it.

However, you could easily have googled this.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Why don't you google like I asked?

Try this.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

First off, your response has nothing to do with the OP's problem.

Secondly, don't resurrect two year old threads unless you have something amazingly earthshaking to contribute.

Duoas 1,025 Postaholic Featured Poster

Your indentation is horrific. Try this:

for(color; color < COLUMN_MAX; color = COLORS(color+1)) {
	cout << setw(7);
	convertToColors(color);
	}
cout << endl;

for (maker; maker < ROW_MAX; maker = MAKERS(maker+1 )) {
	cout << setw(10) << left;
	convertToMakers(maker);

	for (color=Red; color < COLUMN_MAX; color = COLORS(color+1)) {
		infile >> carsInStock[maker][color];
		cout << setw(7) << carsInStock[maker][color];
		}

	cout << endl;
	}
//}  <-- what's this?

After reformatting, it looks OK.

Please, pay attention to how you indent your code. It is a visual cue both to yourself and to anyone else who reads it --a visual cue to help understand what the code does. Many beginner mistakes are directly caused by mis-formatted code.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You can't read from an output file. Data goes out, not in. That's the whole point.

You can create a file that has both read and write access. fstream inAndOut( "fooey.txt", ios::in | ios::out | ios::trunc ); But that's a different thing.

(BTW. I put that ios::trunc flag in there because you might find it handy when doing your homework. It causes the file to be overwritten every time you open it, so it operates like an output file, but with read access.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You'll need two separate loops. One to display the heading, then a nested loop to display the rest of the information.

Please try the graph paper approach. It will help you figure out exactly how to format your output.

Duoas 1,025 Postaholic Featured Poster

First, don't say ios::in . It is implied by the type of stream you are opening.

Second, getline() isn't defined on output files.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes, you can do it in a loop. The trick is making things line up nicely.

For this kind of exercise, I usually find it best to get out a piece of graph paper and decide where each character in the output should be. I notice you are using the setw() manipulator. Good job. You'll also want to output some strategically places spaces and the like to make your header line up.

Good luck.

Duoas 1,025 Postaholic Featured Poster

There's no way in a for loop, since the (first,last) is a special case. Also, watch your index bounds and maintain your result's aggregate value:

double ClosedPolyPerimeter( double x[], double y[], int N ) {
  int i;
  double result = sqrt( sqr( x[N-1] -x[0] ) +sqr( y[N-1] -y[0] ) );
  for (i = 1; i < N; i++)
    result += sqrt( sqr( x[i] -x[i-1] ) +sqr( y[i] -y[i-1] ) );
  return result;
  }

This code first calculates the special case of distance(N-1,0), then uses the loop to calculate the remaining distance( 1..N-1, 0..N-2 ) and add them each to the result.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The example you posted on the last page compiled and worked fine for me using Delphi, but FPC choked... I'm not sure why yet. I've recently upgraded FPC and I think I might have goofed something. I still need to play with it more...

Duoas 1,025 Postaholic Featured Poster

Are you taking a course or just doing this on your own?

You need to watch a few things. First, though, your strcopy should look like this:

strcopy:	lbu	$t0,($a2)	# load the char at $a2
		sb	$t0,($a3)	# save the char at $a3
		addi	$a2,$a2,1	# next $a2
		addi	$a3,$a3,1	# next $a3
		bgtz	$t0,strcopy	# do it all again?
		jr	$ra		# return to caller

If you don't already have a good MIPS reference you need to get one. It makes all the difference.
This one at WikiPedia is short, but good.

1. Every jal should be to a subroutine that returns with jr $ra. Using jal means that you don't need moo: at all.

2. The link I gave you gives the general meaning of all the register names.

3. The syscall to print the string requires $a0 to have the address of the string to print and $v0 to have the value 2.

The syscall to terminate the program only requires $v0 to have the value 10.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

C and C++ purists tend to get heated about terminology for this stuff, but the difference is:

A parameter is the name of something passed to a function. void foo( int a_number, bool is_prime ) a_number and is_prime are parameters.

An argument is the value you pass to a function: foo( 42, false ); 42 and false are arguments. Th

(In C they call them "arguments" and "argument values" respectively.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I don't have any algorithm for base64. It wouldn't matter anyway, because the only difference between 64/100/etc. is the radix. Just make it an argument to your function.

The character set used also matters, so I would make it an argument also.

To equally separate lines, just count off how many times you write to file. After 10 or 20 or whatever, output a newline and reset the counter.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Do try to compile your code before posting here. Once you fix it so that it compiles, post again.

(an lvalue is the variable name to the left of an equal sign).

Duoas 1,025 Postaholic Featured Poster

If your window procedure is small, then that way is an advantage because it is, in fact, less typing.

If your window procedure is very long then it is a disadvantage only because it separates what "info" is from where it is used.

But you are correct, they are otherwise identical.

Duoas 1,025 Postaholic Featured Poster

No, you'd have to roll your own. Try googling for "delphi barchart component". If that doesn't help, I'll see if I can whip-up something simple for you.

An edit component isn't going to display anything but text.

Duoas 1,025 Postaholic Featured Poster

Most older HLLs make a distinction between a function and a procedure. One returns a value, the other does not.

In C and C++, a procedure is declared by returning void (that is, it doesn't return anything): void my_proc() and, of course, a function: int my_func() In Pascal, they are: procedure my_proc; and function my_func: integer; Here's an example:

function intpow( base, exponent: integer ): integer;
  // Raises 'base' to the 'exponent' power
  // and returns the result.
  begin
  if exponent < 0
    then result := 0
    else begin
         result := 1;
         while exponent > 0 do
           begin
           result := result *base;
           dec( exponent )
           end
         end
  end;

Using this function, I can calculate any non-negative exponent that fits in an integer:
intpow( 2, 0 ) --> 1
intpow( 2, 1 ) --> 2
intpow( 2, 2 ) --> 4
intpow( 2, 3 ) --> 8
etc.

Did this help? Or did I misunderstand you?

Duoas 1,025 Postaholic Featured Poster

Sounds like the Dev IDE is too stupid to realize that you have made a console program. I refuse to use Bloodshed anything, so I don't know anything about the program, but there should be something in there to keep the console visible. Poke around the menus and see if you can find it.

The other option is just to add

write( 'Please press ENTER to quit.' ); readln

to the end of your program (just before the end. statement). The analogy to Hello World is exactly right --the same thing is happening.

Hope this helps.