Duoas 1,025 Postaholic Featured Poster

Your syntax needs help. See the C++ FAQ Lite.

The difference between a regular class or function and a template class or function is just that you have template<typename Foo> in front of it, and can use Foo as a generic type instead of a specific type like int, or string or somesuch.

So:

//print an array of ints
void printa( int a[], int len ) {
  for (int i = 0; i < len; i++)
    std::cout << a[ i ] << std::endl;
  }

can be made to print any printable thing by turning it into a template function:

//print an array of any printable thing
template<typename PrintableThing>
void printa( PrintableThing a[], int len ) {
  for (int i = 0; i < len; i++)
    std::cout << a[ i ] << std::endl;
  }

Now I can print arrays of strings, floats, etc...

Compare the difference between the two functions, read your textbook over again, and look at the C++ FAQ Lite page I gave you. Also, use the word "typename" instead of "class" in your template declarations.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You typed "port()" but I think you meant fork().

That's an OS-specific call. On Windows you have to use CreateProcess().

If you are just doing homework at home, you can ssh into your school and do it over the internet, or you can download Cygwin or MSys to compile it with the GCC (which is likely the same compiler you are using at school).

I use MSys myself and if you want more info about installing it let me know. (It's relatively easy and doesn't do anything weird to your Windows box.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Before go off trying to implement your own RTF parser you might want to tell us what exactly you want to do.

Are you trying to simply display a form with a bulleted list?
Are you trying to create a document to save to disk?
Are you trying to embed and modify an external document?

Pascal is very strict when it comes to types. This is only my guess, because I know nothing about the types you are playing with, but they look like classes to me. If they have the same hierarchy then they may be assignment compatible --in which case you will have to explicitly cast one to the other. Otherwise you are trying to mix apples and oranges --in which case there should be another way to do what you want.

It is good that you are googling for information, but make sure you get some direct documentation on the OLE classes you are using (OLEVariant, ListTemplate, etc.).

I don't wish be a spoiler, but I've done RTF programming, and it isn't as simple or as organized as all that. It requires a great deal of organization and some pretty sophisticated lexing, more than it appears you are ready to handle right now.

Duoas 1,025 Postaholic Featured Poster

Yes, yes, of course.

I just noticed that LSIZE is 4. That means your string can't have more than 3 printable characters in it, plus the null at the end. It is waaay too small.

#include <stdlib.h>
#include <stdio.h>

#define LSIZE 200

int main() {
  char inputstr[ LSIZE ];
  char message[ LSIZE ];
  double d;
  int i;
  char c;

  printf( "Please enter a number" );
  getline( inputstr );
  d = atof( inputstr );
  strcpy( message, inputstr );

  getline( inputstr );
  ...
  strcat( message, ", " );
  strcat( message, inputstr );
  ...
  ...
  puts( "The THREE strings you just entered are:" );
  puts( message );
  ...
  puts( "Again, the THREE things you just entered are:" );
  printf( "%g, %d, %c\n", d, i, c );

  return 0;
  }

You'll notice that this code does things two different ways. Choose one.

[EDIT] man, too slow again... :)

Duoas 1,025 Postaholic Featured Poster

Er, the standard way to do it is to use a vector or a deque. These automatically size to fit and allow you to add or remove elements very easy from the back (and front if a deque), and middle without too much trouble. Both can be accessed with the [] array indexing operator, are fast, don't require you to manage their memory, and have only one "disadvantage" over an array (or a newed array): they can't be treated as a pointer. Additionally, deques allow you to work with arbitrarily large amounts of data (or numbers of particles) without any increase in time.

If you want to be throwing random numbers of particles around, I suggest you use a deque, not an array (whether new or not).

Good luck.

Ancient Dragon commented: very well said +20
Duoas 1,025 Postaholic Featured Poster

Oh yeah, (sorry for the double post)

If you still want to fail if any pixel is white

// test here to see if the image can be brightened or not
bool can_brighten_image( char *image, int rows, int cols ) {
  for (int i = 0; i < (rows *cols); i++)
    if (image[ i ] == '0') return false; // there's a white pel, so NO
  return true; // no pels are white, so YES more brightening possible
  }
Duoas 1,025 Postaholic Featured Poster

Your code was fine without the extra { and }. Your indenting could have used a little help though. Take a look at my example in post #5.

I think you are trying to do too many things at once.

If I understand what you want correctly
You have an image stored as an array of array of char, where each char/pixel has a value from '0' (white) to '9' (black).

You want to "brighten" the image, but only if there are no '0's in the image.

You also want to display the image using specific characters (in other words, '0' displays as ' '; '1' displays as '-'; etc.)

Thoughts
Brightening doesn't make much sense for ASCII art.

Brightening is a lossy function, where shades move towards white. Saying that an image cannot be further brightened is rather non-sequitor, unless the image is already pure white. Hence: 0-->0, 1-->0, 2-->1, 3-->2, etc.

Separate the function that modifies the image and the function that displays the image.

// test here to see if the image can be brightened or not
bool can_brighten_image( char *image, int rows, int cols ) {
  // in this example, I'm testing whether or not the image is pure white already
  for (int i = 0; i < (rows *cols); i++)
    if (image[ i ] != '0') return true;  // there's still non-white pels, so YES
  return false;  // all pels are white, so NO more …
Duoas 1,025 Postaholic Featured Poster

There's no reason you can't separate them.

int i;
double d;
char c;
printf( "Please enter a number\n" );
getline( message );
d = atof( message );

printf( "Please enter an integer\n" );
getline( message );
i = atoi( message );

printf( "Please enter a character\n" );
getline( message );
c = message[ 0 ];
Duoas 1,025 Postaholic Featured Poster

If you are still going to mess with it...

Forget the console app, initialization and finalization, and all those other loops.

Just don't bother creating any forms. Don't call application.run.
Just do your stuff in the application .dpr file's begin..end block, and let the program terminate naturally when it hits the end.

program fooey;
uses Classes;
var
  foo: tFileStream;
  s: string = 'Hello, world!';
begin
foo := tFileStream.create( 'fooey.txt', fmCreate or fmOpenWrite );
foo.write( pChar( s )^, length( s ) )
end.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Good question! :-/

I do have to hit it fairly hard, and regularly. Sometimes with a good, heavy bludger. ;)

Duoas 1,025 Postaholic Featured Poster

Best answer is, don't do that.

You are playing with undefined behavior. For any single variable, there should be a maximum of one pre/post increment/decrement operator. Otherwise your results may vary: You could just as easily have gotten 1 2 3, 1 3 2, 3 1 2, 2 1 3, or 2 3 1.

The actual reason you are getting 3 2 1 is because your compiler plays with the arguments in the same order they must be pushed onto the stack to call a c-function. However, that's just one compiler. Others could easily give you different results. (Heck, the same compiler could give you different results at different times.)

Therefore, better to say:

int a = 1;
printf( "%d%d%d", a, a+1, a+2 );
a += 3;

This avoids the undefined behavior of multiple pre/post inc/dec ops for a single variable in one statement.

Hope this helps.

Salem commented: Good answer +11
Duoas 1,025 Postaholic Featured Poster

As long as your array has to be a strict C-type array you must use a loop to initialize it, whether you are using C or C++. That guy's syntax is still wonky.

If you use a vector or a deque though, you can initialize it directly:

#include <iostream>
#include <deque>

using std::deque;
using std::cout;
using std::ostream;

class CParticle {
  public:
    CParticle( int x = 0 ): m_x( x ) { }
    friend ostream &operator << ( ostream &outs, CParticle &p );
  private:
    int m_x;
  };

ostream &operator << ( ostream &outs, CParticle &p ) {
  cout << p.m_x; 
  return outs;
  }

int main() {
  int inits[] = { 1, 2, 3, 4 };
  deque<CParticle> parts( inits, inits + 4 );  // array is 4 elements long

  for (int i = 0; i < 4; i++)
    cout << parts[ i ] << '\n';

  return EXIT_SUCCESS;
  }

For just 100 elements, a vector would do just fine, but if your list is going to be very large, use a deque.

Good luck.

[EDIT] If you get rid of that new keyword and make it an array and not a pointer then the original syntax should work fine. CParticle parts[ 100 ] = { CParticle( 1 ), CParticle( 2 ), ... };

Duoas 1,025 Postaholic Featured Poster

An array is just an ordered list of things. So for the array to be serializable the elements of the array must be serializable. Hence, your conclusions 1 is correct. Conclusion 2 is correct for all elements in an array (not just objects).

However, conclusion 3 needs a little help: Primitive types are serializable by default whether or not they are stored in an array. Therefore it follows that any array made of primitive types is also serializable.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yeah, listen to Ancient Dragon. Sounds to me like you've got yet another bad instructor. The guy needs to go read his own textbook.

Follow AD's code, but if you want to have different initializers for each object, use an array:

int main( int argc, char *argv[] )
{
  int CParticle_initializers[ 100 ] = { arg1, arg2, arg3, ... }
  CParticle *parts = new CParticle[ 100 ];
  for (int i = 0; i < 100; i++)
    parts[ i ].initialize( CParticle_initializers[ i ] );

  ...
  return EXIT_SUCCESS;
}

Good luck.

Duoas 1,025 Postaholic Featured Poster

Yeah. As far as I am concerned, the computer is there to serve me, not the other way around. ;)

The MS article you linked references only which files may be corrupted for the error to occur. QBasic has always used EDIT.COM or EDIT.EXE to do its editing. Version 1.1 is where the editor was rewritten.

Have you tried just going to the command prompt and typing help qbasic.hlp ? If that works, then it is definitely EDIT... If not, then it is definitely a corruption in one of the listed files...

Let me know what happens.

Duoas 1,025 Postaholic Featured Poster

Google "socket programming in c"

Does it have to be in C? Python makes sockets trivial, whereas in C it is a messy pain.

Good luck.

Duoas 1,025 Postaholic Featured Poster

SGDT is 0F 01 /0.
SIDT is 0F 01 /1
LGDT is 0F 01 /2
LIDT is 0F 01 /3

The /0, etc. refers to the R/M field of the ModR/M byte of the opcode. So SGDT would be coded as 0F 01 00 followed by three or four bytes (depending on the operand-size attribute) containing the address of where to store (or load) the global (or interrupt) descriptor table. Likewise, LGDT would be coded as 0F 01 02, followed by an address.

You need to find yourself a good reference. Make sure to look up the ModR/M byte format and the operand-size attribute bytes. Also, these are protected-mode opcodes, so you'll have to code appropriately.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Make sure you are using a good reference when you use interrupts. Also, try to reduce the number of instructions you use.

;set the video mode to CGA 80 x 25, 16-color
mov ax, 0300h
int 10h

;wait for a keypress
mov ah, 1
int 21h

;clear the screen to a specific character attribute
mov ax, 0600h  ; scroll all lines up == clear screen
mov bh, 07h    ; light gray on black
mov cx, 0      ; upper-left = 0, 0
mov dx, 184Fh  ; lower-right = 24, 79
int 10h

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Ah, well, I would suggest googling "XRC editor" and checking out SourceForge. There are a number of open source XRC editors available.

You should be aware, though, that XML isn't a picture file format. If you save a BMP in an XRC file it is still a BMP, just mime-encoded so that it can be handled as text. What that does, actually, is increase the size of your BMP file...

If you still want to do it, maybe it would be easier just to use one of those editors to add your BMP to a form, save it, then with a text editor just copy out the part with the saved image?

However you decide to do this, good luck.

Duoas 1,025 Postaholic Featured Poster

No, he is using a package called graphics.py. It is designed for beginners, so it is fairly convenient and simple to use. The getMouse() function waits for you to click and returns the coordinates. That is why it would be easy to say:

get click one
get click two
draw house rect
get click three
draw door rect
...

Duoas 1,025 Postaholic Featured Poster

Time enough has passed that I haven't answered here.

As I mentioned already, the reason you see a button on the taskbar is because the application puts it there. Your forms don't. You can see this by going to the main menu --> Project --> Options --> Application --> Title and giving your application a title that differs from the main form's caption. The button on the taskbar will show the application title, and not the mainform caption.

When you have MDI children, which cannot be hidden, the application button is restored to the taskbar because you technically still have windows showing... even if the MDI main form is hidden.

So, to get rid of it you have to turn it off explicitly. In MAIN.pas, make sure you have the following:

interface
type
  TMainForm = class(TForm)
    procedure ApplicationActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private:
    procedure SysCommandMessage(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
  protected:
    procedure CreateParams(var Params: TCreateParams); override;
  end;

implementation

procedure TMainForm.ApplicationActivate( Sender: TObject );
  begin
  // Remove the application button from the taskbar
  // (and make sure it stays that way)
  ShowWindow( Application.Handle, SW_HIDE )
  end;

procedure TMainForm.FormCreate( Sender: TObject );
  begin
  // Keep the application button out of the taskbar
  application.OnActivate := ApplicationActivate
  end;

procedure TMainForm.SysCommandMessage(var Msg: TWMSysCommand);
  begin
  // Routing WM_SYSCOMMAND messages through here instead of the default
  // handler prevents Delphi from trying to create a taskbar button for the
  // application when minimized and maximized, which when combined with
  // ApplicationActivate would otherwise cause flicker. …
csy commented: Helpful +1
Duoas 1,025 Postaholic Featured Poster

Ah, yes. That would do it. ;) Glad you caught that.

Duoas 1,025 Postaholic Featured Poster

If it is from any of the DOS 6.x series or Windows 9x then it is QBasic 1.1. However, the editor (EDIT.EXE) changed for Windows 9x. Since DOS 6 is a 16-bit OS and Win 9x is 32-bit, you might want to search the web for the later editor. I'm using the 2.0.026 version of EDIT.EXE, copyrighted by MS in 1995. It doesn't have the WordStar diamond, but takes all the WordStar keys just fine...

Good luck.

Duoas 1,025 Postaholic Featured Poster

Er, yes. Both my first post and the entire second half of my second post were dedicated to that option, which I also feel is best.

However, if he is unwilling to do that, a global is the next best thing, especially considering his apparent skill level. When he learns more he'll be doling out advice like us.

And, er, mank, you need to give things better names than "container" and "func1" and the like. If you don't know what something should be named then you likely have only a vague idea of what it should be doing... which I think is part of your difficulty.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Pointer syntax in C/C++ is very flexible, but likewise very confusing. You can say something like int i, *pi, **ppi; but this should be read carefully as

int i;
int* pi;
int** ppi;

:an integer, a pointer to an integer, and a pointer to a pointer to an integer. Yeah, I know... read it again anyway... (I attached the "*" to the int because it is part of the type of each variable, but it could be anywhere between the base type and the variable name.)

In C, you are forgiven a lot when dealing with the type of things. Hence, as already mentioned, the variable int* pi can be a pointer to a single integer or a pointer to a whole lot of them. Typically, programmers will state their intent by saying either int *a --pointer to a single int, or int a[] --pointer to an array of ints.
However, you can't use the [] brackets when declaring a function return type, so you are stuck with the *.

Hope this helps.

zandiago commented: pretty decent breakdown +1
Duoas 1,025 Postaholic Featured Poster

part one
Don't load "asteroid.bmp" from file every time you call DrawBitmap(). That's a huge slowdown. Load the bitmap first, (say in Game_Init()) and have DrawBitmap() take a handle to the bitmap to draw instead of a filename.

Don't forget to use DeleteObject() before terminating to get rid of the bitmap.

part two
To animate the asteroid moving about smoothly, you need:

1. a direction to travel. This should be (x, y) pixel offsets. Use floats, and round to the nearest integer before mapping the image. (If you use only integers your asteroid is limited in how fast or slow it travels.)

2. (possibly) a time to travel that distance. In the original asteroids game, the rocks only changed direction when impacted (hit by another rock or by the ship's weapon fire), so the time the asteroid traveled its direction was infinite, hence unnecessary to bother tracking. However, if you want it randomly changing direction, when time is up calculate a new direction to travel.

Next, you need to calculate the (x, y) direction --randomly if so desired-- then begin moving the asteroid's position by adding the (x, y) offset each frame. All you need to track is the previous asteroid location. You know the bitmap's width and height, so use FillRect() to blacken the previous image, update the asteroid's location, then BitBlt() the asteroid to its new location. Consider how you want it to react when it reaches the edge of the …

Duoas 1,025 Postaholic Featured Poster

Since no one else has answered this...

I am not familiar with using MatLab. (I presume you mean MatLab.) However, you should be aware that affine transformations are matrix multiplications applied to an affine space --that is, applied to vectors.

A vector can be any dimension you want. Your transformation matrices just need to match.

There is no one, obvious way to turn 2D data in to 3D data. You would probably do best to "grow" a fern instead of trying to "paint" a fern. You might want to check out 3D tree generators like arbaro.

Good luck.

Duoas 1,025 Postaholic Featured Poster

Your []'s are in the wrong spot. Say

DisplayArrays( studentNames, scores );

and

double DisplayArrays( string studentName[], int score[] )

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I'd be interested to know why application.terminate didn't stop your program. Have you got unusual hooks in there somewhere? Did your code actually call it?

The problem with the timer is that there is a system limit on the number of timers available. It doesn't matter how big your application is.

Duoas 1,025 Postaholic Featured Poster

If I understand you correctly, you want to define the array and fill it with values in, say, funct1(), then use it elsewhere in, say, main().

You can't do that. The array is local to the function in which it is declared. Hence, it only exists while that function is actually executing. Once the function terminates, the array disappears, and all the pointers you have pointing at it become useless.

The only ways around it is to either define it as a global array (recommended), or use malloc() to create it (meaning you'll also have to free() it later). I don't recommend the second method because all it does is the same as a simple global but with all the grief of memory management and circular thinking --and you are still struggling with the basics. So stick with what is simple.

In general though, you should declare data before you use it, in the function in which you are going to use it. Hence:

int main() {
  float container[] = { ... };
  int i;

  do_something_to_container( container, length_of_container );

  for (i = 0; i < length_of_container; i++)
    cout << container[ i ];

  ...

(Please note that this is pseudo-code. For example, I never defined length_of_container or do_something_to_container(). You are expected to replace these with the correct things.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You aren't thinking it through.

Do this:

if (decision == "B" || decision == "b"){
    for (k =0; k < rows; k++){
        for (m =0; m < cols; m++)
            if (image[k][m] != 0)
                switch (image[k][m] = image[k][m] + brightcount){
                    case '0' : cout <<" "; break;
                    ...
                }
            else cout << ' ';  // image can't be brightened further
        cout << "\n";  // done this row
    }
}

In pseudo code:

if decision is B or b:
  for each row:
    for each colum:
      if given pixel != 0:
        modify pixel and display something (other than the modified pixel value)
      else: display a blank
    put out a newline at the end of the row

I'm still confused about how you are storing the colors of your image. If they are characters, then how is '\0' the brightest possible value? It can't even be displayed...

Is this supposed to be some sort of ASCII art transformation?

Duoas 1,025 Postaholic Featured Poster

"Graphics" is a huge category. What kind of graphics do you want to do? Windows and buttons and scrollbars? 2D picture processing? 3D animations? Video games? ASCII art?

I ask because C++ doesn't do graphics. C++ can use libraries that do graphics. Depending on what you want to do we can point you in the right direction.

Duoas 1,025 Postaholic Featured Poster

You are going to have a hard time shell scripting if you are unwilling to read about basic commands like for. Rd won't see "*" unless you somehow manage to name a directory "*".

I did also mention that basic testing was needed... which I have now done. Change every %%dir to read %%d . Apparently the command interpreter didn't like me using a variable name with more than one letter to its name.

Also, you might want to add @echo off to the top of the script so you don't see every command as it is executed.

VERY IMPORTANT
And before you run it make sure that you get the "Administrator" and "All Users" and any other directory you don't want deleted in there spelled correctly and capitalized correctly. If not you'll regret it.

Duoas 1,025 Postaholic Featured Poster

>>And whats the difference in malloc and calloc?
calloc() calls malloc() then initializes the data to all 0s.

Please read answers given to you. And don't quote yourself...

A computer program is loaded into several parts of memory. There is the code (functions and the like), data (global variables and the like), the stack (local variables and the like), and the heap.

The heap is just a big block of unused memory that your program is allowed to use. When you call malloc() it takes a chunk of the heap and marks it as 'allocated', and returns a pointer to the part of the heap memory you can use. When you call free() that piece of heap memory is unmarked and available for malloc() to use again.

So for your example, you ask for n *sizeof( float ) bytes of the heap. The pointer p points to the first part of the heap you are allowed to use for your array of floats.

Duoas 1,025 Postaholic Featured Poster

You'll have to enable command extensions and use the for command. Works on XP.

:: change to the proper directory (probably C:\Documents and Settings\)
%SystemDrive%
cd "%ALLUSERSPROFILE%\.."

:: for each subdirectory name except "Administrator" and "All Users" do delete it
for /D %%dir in (*) do (
  if not "%%dir"=="Administrator" (
    if not "%%dir"=="All Users" rd /s/q "%%dir"
    )
  )

This is untested... you may have to tweak it some.

Good luck

Duoas 1,025 Postaholic Featured Poster

There isn't one.

GetDiskFreeSpace() is an OS-specific function. If you are looking to find free disk space in linux, google statfs(). That's not a standard function anywhere, but it is a common extension to System V. It obsoletes ustat(), which also does the job.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You have some serious syntax errors going there. This is my best guess as to what you mean:

function Rus( mes: string ): string;
  var i: integer; // number of processed character
  begin
  for i := 1 to length( mes ) do 
    case mes[i] of
      'A'..'Z', 'a'..'n': mes[i] := Chr( Ord( mes[i] ) - 64 )
      else                mes[i] := Chr( Ord( mes[i] ) - 16 )
      end;
  rus := mes
  end;

Notice also that I separated the test case into a list of test cases for capital letters, lowercase letters, and if you want cyrillic letters, test them separately as well. Google ISO-8859-1 to see where they appear in the codeset.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The best way to terminate an application is to call application.terminate This prevents a lot of problems and can be called anywhere.

Avoid using tTimer as much as possible because it is a "heavy" object --chewing up resources and time.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The switch statement itself has an expression unconditionally modifying image[k][m], so you will have to add an if statement before the switch:

if (image[k][m] != 0)
  switch (image[k][m] = ...) {
    ...
    }
else cout << " ";

You also need to watch your indentation. The

cout << (image[k][m]);
cout << "\n";

lines belong to the outer for loop, not the inner loop. Hence, it will only output once for each row, and m will always equal cols (which I am thinking is an invalid index).

I am also wondering what type the elements of your image array are. Are they ints or chars?

Duoas 1,025 Postaholic Featured Poster

One other thing, we hadn't eveb touched vectors and arrays yet, Duoas, had to look that up in the book, looks faster than the way we're doing it.

Er, I expected you to look it up, but the point was that you don't need to use any of it. You will get to them before too much longer in the semester. But it is never faster to use data structures when you don't need to...

You have a very good start. You need to watch for two things: syntax and indentation.

The do...while loop only takes a condition at the end of the loop. All the stuff with the count variable must be moved elsewhere (before and inside the loop). Also, you need to watch your termination conditions. As it is, (if it worked, that is), count will always be larger than the number of numbers entered by one. Think about it. (What if the very first number entered was -99.9? Count would be 1 when it should be 0. What if the very second number entered was -99.9?) A related problem is that when the user does enter -99.9, it is added to the total.

With that in mind, try using a loop like:

int count = 0;
while (true) {
  cout<<"Enter a real number of -99.9 to stop:"
  cin >> input;
  if (input == -99.9) break;
  total += input;
  count++;
  }

Finally, look up functions in your textbook again. You should be getting the …

Duoas 1,025 Postaholic Featured Poster

Make sure you go read the stuff at the C++ FAQ lite that I linked for you.

Use the word typename instead of class in template declarations. Yes, I know... semantics...
Somewhere you should have something that looks like this:

template<typename Type>
class orderedLinkedListType {
  ...
  nodeType<Type> first;
  int count;
  ...
  public:
    void insertNode( const Type & );
  ...
  }

Notice that both first and count are declared in the class. Make sure that they are in your code also. (I didn't know exactly where to put them. It is OK if they are after the public keyword.)

Also make sure that count is an integer (it is the thing being post-incremented: count++; ).

On line 28 the nodeType items are being compared with the >= operator. Make sure your nodeType template class overloads that operator properly.

You don't need to insert the { and } that Lerner suggested, but I would recommend being more careful with your indentation. (The else is missing a tab indent.)

Let me know if this helps. Good luck.

Duoas 1,025 Postaholic Featured Poster

Without seeing your code I can't really give further help.

SSH just lets you connect to another computer. It shouldn't affect your compiler. That said, though, you might not be using the same compiler on both ends. For example, say you are at home using Windows and make a program with VC++. Then you use SSH to connect to the school computer running Linux. If you copy the program source files over there and try to compile on the school's computer you will not be using VC++ but likely GCC or some other OS-specific CC. If your code isn't strictly ISO compliant you will have problems.

I presume you know this and that I am only stating the blaringly obvious but easily overlooked.

Duoas 1,025 Postaholic Featured Poster

Hmm, I hadn't considered different versions. I'm using QBasic version 1.1, and everything is just piled in one folder on my G: drive. I run it from the default windows command prompt.

What version are you trying to work with?

Duoas 1,025 Postaholic Featured Poster

In C, an array variable is a pointer to the first element of the array. Hence, you can treat the variable as any other, keeping in mind that manipulating the array variable is different than manipulating the array elements.

float *reverse_it( float *a, int len ) {
  float x, *b, *c;
  for (b = a, c = a+len-1; b < c; ++b, --c) {
    x  = *b;
    *b = *c;
    *c =  x;
    }
  return a;
  }

void print_it( float a[], int len ) {
  int i;
  for (i = 0; i < len; ++i)
    printf( "%f\n", a[ i ] );
  }

int main() {
  float container[ 4 ] = { 0.1, 0.2, 0.3, 0.4 };

  print_it( reverse_it( container, 4 ), 4 );

  return 0;
  }

Notice how float *a and float a[] are exactly the same thing? The reverse_it function manipulates the array by directly using pointers to the elements of the array. The print_it accesses the array elements by subscripting the array variable. Saying a[ i ] is exactly the same as *(a+i) .

The other thing to note is that reversing the array actually changes the array in main. That's because container is a pointer to the elements of the array, not the elements themselves. So even though you may have multiple copies of the pointer lying around (two separate variables named a and also b and c) there is ever only one copy of the array itself.

I hope this makes sense.

Duoas 1,025 Postaholic Featured Poster

Write the values to a file from your program.

ofstream outs( "data.txt" );
outs << value1 << "\n" << value2 << std::endl;

Choice of shell matters. Here I use bash and awk.

value1=`awk 'NR==1' data.txt`
value2=`awk 'NR==2' data.txt`

If you want to avoid the file on disk, you can always write to std::cout and pipe the result into awk. Etc.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I haven't messed with VC++ for a long time, but I believe it comes with some form of make.

Open a command window and make sure the VC++ bin directory is in the path (the directory that has all of VC++'s exe files), and type make as usual.

MS and Borland versions of make are significantly underpowered (as is usual on Windows). If you are trying to compile someone else's cross-platform code then the stuff that comes with VC++ might not hack it. If your build process fails (particularly if it uses autoconf, configure, or other like utilities), you will have to get the GCC.

If you are just trying to compile homework between home and school the VC++ stuff should work fine.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

This is actually one of the most insidious problems people learning C/C++ get.

The problem is one of type.

1/2 is integer
1/2.0 is floating point

So, for example, when you go to calculate the PDF you say pdf=((1/2)+INV_SQRT_2PI * ... That one-half there is an integer expression, which gets promoted to double after it is evaluated. Hence, 1 idiv 2 is 0, promoted to double is 0.0, + INV_SQRT_2PI etc..

All the places where you have something like /2 check to make sure your numerator is a double before division occurs. If it isn't, change your denominator to a double (say, /2.0 ).

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I'm running XP and QBasic and help work fine for me. I can't reproduce your problem. Sorry I can't help you further...

Duoas 1,025 Postaholic Featured Poster

It looks like you are playing with template classes. You might want to read up on templates over at http://www.parashift.com/c++-faq-lite/

The first problem is that there is a variable or class or function named first being used somewhere in the code (lines 43, 74, 116) that either doesn't exist or exists in another namespace.

The second problem is that with templates, you don't know what the type is, so you use a substitute. For example

template <T> T succ( T a ) {
  return ++a;
  }

int i = 42;
std::cout << succ( i );  // works great: prints 43 and i still == 42

std::string s = "Hello, world!";
std::cout << succ( s );  // fails miserably

Somewhere in the code a variable of type Type is being post-decremented ( x-- ). If x is, say, a string then the template fails, since decrementing a string is not defined (it makes no sense).

Duoas 1,025 Postaholic Featured Poster

The strrev() function is somewhat more common on windows. In linux you have an even shot of having it and not having it. It isn't in the ISO standard (AFAIK).

Here's a simple strrev:

char *strrev( char *s ) {
  char *u, *v;
  char c;
  for (u = s, v = s +strlen( s ) -1; u < v; ++u, --v) {
    c = *u;
    *u = *v;
    *v = c;
    }
  return s;
  }

You could combine the strcpy() and strrev() functions into one function to reverse and copy a string at once...

Also, iamthwee makes a good point. Make sure you are compiling with -Wall to see all errors you can get. Windows compilers are notorious for letting you get away with improper headers.

All these palindrome programs --isn't this too strict? After all "A man, a plan, a canal: Panama!" is a palindrome, but none of the programs posted so far considers ignoring punctuation and spaces. Ask your professor "Can I attain a 'C'?".

Salem commented: I like the last palindrome :) +11