Duoas 1,025 Postaholic Featured Poster

Hey there, if you're still interested, don't give up.

I wrote it originally in Object Pascal, and I used a number of very powerful container classes that don't exist in C (...obviously). So I've been coding a replacement for them also... (It's kind of boring actually...)

I should be done pretty soon. Once I give it some basic testing I'll wrap the whole thing up for you and respond here again.

Duoas 1,025 Postaholic Featured Poster

Only if you don't check the size of the buffers. Notice how I carefully allocated space large enough for either string before copying? That, and the strings in argv[] are guaranteed to be null-terminated. No problems.

All pointer arithmetic is inherently dangerous. But it is how the machine works. You can take the time to do it right (which includes using functions that do all the checking for you, which don't exist in the standard library in this case). That doesn't justify auto-hatred of specific functions (well, except gets() and the fabled void main(void) ).

My latest example is safe also, because the target string is longer than the source --hence the niftiness of it for you.

(Again, results may vary for your compiler. If using GCC make sure to use the -fwritable-strings flag.)

Enjoy!

Duoas 1,025 Postaholic Featured Poster

You sure can. It'll do the same thing it would if you had called it from anywhere else in the code.

But... you shouldn't. It's kind of like Steve Jobs calling up Bill Gates and telling him how to run his business. There isn't any reason peers should be sticking their noses in each other's private places.

What exactly are you trying to do? Perhaps we can suggest a better way.

Duoas 1,025 Postaholic Featured Poster

Your reported errors don't have much to do with the code you are showing me (at least not as far as I can tell --please use [[I][/I]code[I][/I]] blocks when posting).

Are you using Delphi (a.k.a. CodeGear) or are you using FPC? If the former, then you should use the help that comes with Delphi --it is very extensive and provides a lot of examples and is very well cross-referenced. For example, if you look at TForm properties, you'll see there is an ActiveControl property which shows which control currently has focus. The TMemo component has both OnChange and OnKeyPress event handlers you can hook directly into each memo to guard against invalid keys instead of using the form's key preview.

If you are using FPC it still has a good deal of documentation, and you can get the Delphi help files from Borland's website to supplement it.

Also, google around for tutorials and other things related to what you are trying to accomplish. Usually they will help you consider how best to do it and what kinds of things you need to watch out for.

Sorry, I know this isn't exactly the kind of help you expected... alas.

Duoas 1,025 Postaholic Featured Poster

I don't understand why you are confused.
1. You use find_digits to read num1 (the first number).
2. You read a character (one of '+' or '-' or something).
3. You use find_digits to read num2 (the second number).
4. You read a character (one of '+' or '-' or something).
5. You use find_digits to read num2 (the third number).
6. You read a character (one of '+' or '-' or something).
7. You use find_digits to read num2 (the fourth number).

Make sense?

Duoas 1,025 Postaholic Featured Poster

The stack is just a piece of memory where you can push values on the end or pop values from the end. The $sp register always points to the next available spot.
Visually:

[  ]
[  ]
[  ] <-- $sp
[-7]
[12]

If we push 42 onto the stack, we get:

[  ]
[  ] <-- $sp
[42]
[-7]
[12]

Popping a value works in reverse.

MIPS doesn't have any "push" or "pop" commands, you just use lw and sw and directly add or subtract to change the $sp value.

Every procedure/function will look similar:

proc_name: sub $sp, $sp, 4  # push the return address...
           sw $ra, 4($sp)   # ...on the stack

           # (do the subroutine stuff here)

           # (stick any return values in $v0 (and $v1 if needed))

           lw $ra, 4($sp)   # pop the return address...
           add $sp, $sp, 4  # ...off the stack
           jr $ra

Because register 31 ($ra) is preserved on the stack during the function, you can easily call other functions, or even recurse without worry. To call the function, just do the usual: jal proc_name What follows is for your edification, but I don't think you'll need either to do your assignment:

Passing arguments
In MIPS, registers $a0..$a3 are expected to be used as arguments to functions. This is not entirely necessary, just convenient. You could push arguments onto the stack before calling the function as well. If you have more than four arguments, you'll need to push the …

Duoas 1,025 Postaholic Featured Poster

:-/ :idea: ;) Yes, that was the point.

Try compiling with gcc -fwritable-strings stupid.c :)

Duoas 1,025 Postaholic Featured Poster

At this point we'll need to see your code to understand how you are trying to do things...

Duoas 1,025 Postaholic Featured Poster

Why type all the verbiage when you can just use spawnl()?

You need to #include <process.h> Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Cool Narue! I didn't know that. (I suppose that's the kind of brain damage I get for having tried it years ago on some silly, ancient, broken DOS C compiler.)

Doublex, how about this one: printf( "%s", strcpy( "Stupider", "Stupid" ) ); (results may vary).

Duoas 1,025 Postaholic Featured Poster

The "tag" doesn't do anything. It's just a longint value you can use for whatever you like.

I've used it above to uniquely identify the components you wish to change when you click a checkbox item.
So yataykapa1 gets modified by the checkbox whose tag is 1, and yataykapa2 gets modified by the checkbox whose tag is 2, etc.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

scanf() and cin tokenize on whitespace, so yes, they stop reading input at any whitespace. Please don't use gets(). fgets() reads an entire line (it even returns the newline character at the end of the line), so if there are spaces in the line you'll get them too. The C++ equivalent is getline(): string s; getline( cin, s ); Except getline() doesn't leave the newline in the string.

There's no standard function to simply remove whitespace. (Are you thinking of things along the lines of removing leading and trailing whitespace, or do you also want to get rid of internal whitespace?)

If you are using C++, I suggest you check out the Boost String Algorithms Library. It has some stuff that might help.

Otherwise, you'll have to write your own function.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

At the risk of being repetitive for having mentioned this before, you may not have write access to your command line arguments. Moreover, you can't change their size. I think it is perfectly within reason to copy them into local character arrays:

int main( int argc, char *argv[] ) {
  char *s1, *s2;
  int len, len2;

  if (argc < 3) {
    printf( "fooey!\n" );
    return 1;
    }

  /* len <-- size of the longest string */
  len  = strlen( argv[ 1 ] );
  len2 = strlen( argv[ 2 ] );
  len  = (len < len2) ? len2 : len;

  /* get the strings */
  s1 = (char *)malloc( len );
  s2 = (char *)malloc( len );

  strcpy( s1, argv[ 1 ] );
  strcpy( s2, argv[ 2 ] );

  printf( "Given the strings:\n" );
  printf( "1. %s\n", s1 );
  printf( "2. %s\n", s2 );

  /* (do your swap here) */

  printf( "Now the strings are:\n" );
  printf( "1. %s\n", s1 );
  printf( "2. %s\n", s2 );

  free( s2 );
  free( s1 );
  return 0;
  }

That example for the trick is horribly broken, but it works just fine when done right. Keep the sequence points intact, and only try to swap ordinal values of the same size (char s match both criteria):

char a = '1', b = '2';
printf( "%c%c\n", a, b );
a ^= b, b ^= a, a ^= b;
printf( "%c%c\n", a, b );

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You know, there is a whole web site devoted to regex: RegularExpressions.info.

The two most complete standards are Perl and POSIX. Perl is better, and the two diverge a bit, so given the choice choose Perl or Perl Extended.

Most other regexp engines are underpowered and/or domain-specific. (AFAIK)

Duoas 1,025 Postaholic Featured Poster

I think I see what you are trying to do.

You have a list of students, where each student has a name and an ID.

#include <iostream>
#include <vector>
using namespace std;

// This is our student, who has a name and an ID
struct student_t {
  string name;
  long ID;
  // This is a constructor to help us create a new student
  student_t( string aName, long aID ):
    name( aName ), ID( aID ) { }
  };

int main() {
  // This is our list of students. There can be as many
  // or as few students as you like.
  // Initially, there aren't any students.
  vector<student_t> students;
  // (This takes the place of an array
  //  like "student_t students[ 100 ];")

  // Let's fill our array with students
  string s;
  long id;
  while (s != 'n')
  {
    cout << "Please enter a student name: ";
    getline( cin, s );
    cout << "What is " << s << "'s ID? ";
    cin >> id;

    // Now let's create a new student with the information
    // we have and append it to the list of students.
    students.push_back( student_t( s, id );

    // ignore the newline from the last cin. This is necessary
    // because I mixed >> with getline(). The next time I get
    // a student name I want the name, not what was left over
    // on the end of the line when I asked for the ID...
    getline( cin, s );

    cout << "Another (y/n)? …
Duoas 1,025 Postaholic Featured Poster

I think that's actually part of the reason they called them procedures, because Scheme allows side effects...

The use of the word "combination" is another one of those Scheme goodies... But in an evaluative/transformational way of thinking it makes sense... (as Scheme is all about list transformation).

Are you in to program transformation too? (All the Haskell junkies I know are into that.)

They all worry about me because I like my side effects being transparent. I don't want to have to dink with monads for every function that uses a function that may have side effects... That's what compilers are for IMO. :S :)

Duoas 1,025 Postaholic Featured Poster

After writing it in C++, I realized that g++ produces fairly large executables... So I rewrote it in Pascal (compiles with Delphi and FPC, but I used Delphi because it produces the smallest exe).

I also found and fixed a couple of (small) errors along the way (nothing to worry about if you are using the earlier version).

Get the new exe and/or sources from the same link as above.

Enjoy!

Duoas 1,025 Postaholic Featured Poster

I haven't played with it really, but offer only this observation: using floats exactly is playing with fire. And you're stepping on the gas with payment/.01 . If you must use floats, just say payment*100 .

There's a nifty routine called modf() that splits a float into its integer and fractional parts. You could say: while ((modf( payment *100, NULL ) > 0.001) || (payment < 0.0)) That 0.001 is a simple epsilon that lets floating point numbers be their inexact selves...

Please use [[I][/I]code[I][/I]] blocks...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You are on the cusp of getting it.

Num2 can never be more than one number at once. It can be different numbers at different times... it is a different number each time through the loop (you get a new num2, print it, then go through the loop again to repeat).

So your logic steps are good and correct. The problem is there is no array anywhere in there. Hence why you need to go bug your prof.

Duoas 1,025 Postaholic Featured Poster

True. Using a regex would definitely be overkill just to get what he wants...

Just find where in the string "have" starts, and the answer is everything before that...

But like iamthwee advised, you need to decide what language you want to use to accomplish your goal.

Duoas 1,025 Postaholic Featured Poster

Don't be sorry. I'm the one who can't remember whether it takes string or char*.

Don't use <cstdio>. You don't need it.

I already gave the answer for the ifData stream in my last post.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes, the regex is easy, but the code you use makes a difference.

Just use (.*)have . That will match everything up-to and including the "have". The first "capture", or subexpression, is everything except the "have".

Duoas 1,025 Postaholic Featured Poster

You are using the wrong function family. exec() isn't supposed to return.

Use one of the spawn() functions instead.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You've done a fine job of explaining yourself, so don't worry.

Just like Jishnu says, use a simple text file. It can be shaped any way you want. For example:

1 Caitlyn
3 Aislann
3 Colm
6 Seamus
7 Bridget

Each line of the file is composed of:
- a high score
- a name

That format should be easiest to read and write...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Ah, I see. You can do that with a TBitBtn.

Duoas 1,025 Postaholic Featured Poster

Same kind of answer as in your other thread.

For each tCheckBox, set the tag property to 1, 2, 3, etc. as appropriate. Then give them all an onClick event method like this:

procedure tAnaForm.CheckBoxClick( sender: tObject );
  begin
  if tCheckBox( sender ).checked
    then begin
         tLabel( AnaForm.findComponent( 'DIKEYAC' +intToStr( sender.tag ) ) ).visible := true;
         ...
         end
    else begin
         ...
         end
  end;

Again, untested! Of course, I don't know what type of things DIKEYAC and YATAYKAPA are, so I just used "tLabel". You'll need to cast to the correct type of thing...

Also, please use [[I][/I]code[I][/I]] tags...

Duoas 1,025 Postaholic Featured Poster

Look in your documentation for TComponent.FindComponent.

You can say something like:

for i := 1 to 50 do
  tLabel(DisplayForm.findComponent('Label' +intToStr(i))).caption :=
  tMemo(AnaForm.findComponent('Memo' +intToStr(i))).lines[0];

Untested!

Duoas 1,025 Postaholic Featured Poster

First, some thoughts:

Your compiler lets you get away with it, but in C you should generally stick all variables before any code:

int i, n = 0, r;
srand( time( NULL ) );
r = rand() %100 +1;

Don't use (void) in front of printf(). (There's no need.)

You don't need <windows.h> (you aren't using anything in there so it only serves to make your program only compile on Windows).

That return; on line #45 should be a break; Here's a little function for you:

void pause()
{
  int c;
  printf( "Please press ENTER to continue..." );
  do { c = getchar(); } while ((c != '\n') && (c != EOF));
}

Now you don't need to call system("PAUSE") , which is non-portable also...

OK. For your question, you want to keep the top score for each time the game is played. As it is, your program only plays the game once then quits. Is this how you plan to keep it or do you want to have the game play until the user says he's done and only keep top score for that?

If the former, you'll have to create a high scores file (something like "highscore.dat"). When your program starts, open it and read the high score. When your program is ready to end, if the person's high score is better than the last one, rewrite the file with the new high score.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Actually, though, you are right. I've a bad habit of doing that. I don't imagine it to be very understandable to people for whom English is a second language. I'll try to desist. :sweat:

Duoas 1,025 Postaholic Featured Poster

> hey, dont be so rude..
Excuse me? What's rude is posting here demanding that someone to do your homework for you. There is no teacher anywhere that will give you an assignment and not provide you with the means to accomplish it.

What else is rude is giving someone a hard time for refusing to give away code, or to try to make up for a failure to pay attention in class. Please read the Forum Announcements. We are not here to think for someone, or give them a good grade for something they haven't learned.

Instead, require people to do their best, and then assist them in their efforts. Only then do they benefit from good understanding and good grades, both now and in the future. And other people in the future don't have to put up with someone who claims to know what he doesn't.

Duoas 1,025 Postaholic Featured Poster

> What the heck is an erm.

:$ Oh, urgh, um... Exchange Rate Mechanism, Enterprise Resource Management, Erase Reserved Memory, Electronic Rodent Monitoring, Earth Resistance Meter, uh...

:)

Duoas 1,025 Postaholic Featured Poster

I did not at any time post to abuse you, yet you feel the need to abuse me?

> you do not understand assertions at all. ...
Nonsense. You cannot regurgitate my argument as proof against my argument.

> assertions are not error handling devices.
Again, that was my whole point. All the advice you gave the OP was to the contrary.


Pay attention: assert() is to be used when validating design. I love it when people start quoting me about logic and coherency.

Again, I didn't post to personally attack you (nor did I), but only to provide some information about assert() so that people reading this thread don't get lost in hijacked stuff about assert(). I wonder if the original OP is still reading this? To him I apologize for my part in wasting your bandwidth about assert(). You don't need to use it, especially for school assignments.

So believe what you like. Bye now.

Duoas 1,025 Postaholic Featured Poster

sorry, but /me takes deep breath

though assertions have been around for a long time, it is unfortunate that many programmers do not habitually use them.

I wholly disagree.

First, I don't hate assert(). Nor do I hate people using it correctly. Before going further, I'll refer back to a part of the Wikipedia article [ 1 ]. Keep in mind that assert() responds to errors by improperly terminating your program and printing an error message. This is the first half of the flaw it represents. The second half is a failure to understand the actual fallout from such a response.

1. Assert() is habitually taught and/or used as an error-handling device.
The problem with that is that its usefulness is limited to a very small domain. The kind of errors it is expected to catch are a special class: they aren't to check runtime errors, or logic errors, or hardware faults, or subsystem errors of any kind, but programmer errors. What are programmer errors?

They are a failure to design correct and robust code. Plain and simple! Harsh, huh?

Don't feel slighted. Every good programmer recognizes that this is his occupation: to discard bad design decisions and learn correct design decisions. That is part of the process of discovery vital to all software development. Heck, they've even got process models that describe this: waterfall, spiral, iterative, ... there are zillions.

Now, sometimes, particularly when working with an unfinished, poorly tested …

Duoas 1,025 Postaholic Featured Poster

> how would i write a maximum number test function that will take any number of arguments and returns the greatest of them???

I think it would be very odd that your professor wants you to create a function that takes a variable number of arguments. Perhaps you should work with finding the largest number in an array?

Don't use recursion unless your professor explicitly asked you to. I don't imagine he did if you are to work with a variable number of numbers...

To figure out your problem, you have to think about how you, yourself can find the largest number in a list. For example, if I give you the following numbers, which is largest?

1295876
1279553
1295976
1297854

Figure out how you figure it out on your own, and then you can tell the computer how to figure it out. Make sense?

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Rather than a bunch of "if foo = x ... " statements, use a "case foo of" statement:

case oper of
  '+': begin
       ...
       end;
  '-': begin
       ...
       end;
  end;

You've already got a function that will read a number. (You used it to get num1.) Use it to get num2.

While you are moving along quite logically... your current line of thought is taking you toward that recursive descent algorithm that ExplainThat mentioned in joygqy's thread... there are no arrays in sight. If you are not to use records I'm at a loss as to how your professor expects you to use an array. You should take what you've got so far and go see him and ask how he wants you to put your equation into an array.

(Frankly, I think the assignment has a few points that are a little over the top. While simple, it is not trivial, and it is definitely not a beginner-level thing to properly handle mathematical expressions...)

Duoas 1,025 Postaholic Featured Poster

Yes, I totally missed that one. I wouldn't just move it, I'd get rid of it completely. The user shouldn't have to press ENTER more than once per answer, and only when asked...

Good eye!

Duoas 1,025 Postaholic Featured Poster

Hey, I'm sorry. Let me be a little more helpful.

If the stack only permits word values, put your char in the low-order byte of a word and push it on the stack.

When you are in your proc, access the word on the stack containing your char, and just use the low-order byte in the routine.

It looks to me like you are programming on an x86. To return a byte, just put your return value in AL and return as usual.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You are going to have to play with the crt unit. It has procedures and functions that will let you do things to the screen (clear it, move the cursor to a specific location, change colors, etc.)

Good luck.

Duoas 1,025 Postaholic Featured Poster

> Is this correct?
Perfect.

Keep in mind, you don't have to use the same names in your function as you do for the globals. Your function could be:

function find_digits(var c : char; var  f : text): integer;
  Var
    num : integer;
  begin
    num := 0;
    while c in ['0'..'9'] do
      begin
      num := num * 10 + (ord(c) - ord('0'));
      read(f,c);
      end;
    find_digits := num;
  end; { find_digits }

(I made a couple of other changes too, just to show you how you can think of some things...)

> Now, would A loop allow me to get all the numbers from the equation? If I put the loop right after the num1 := find_digits(my_char, my_file);

You are going to have to think about this one with the construction paper and crayons a little bit. What is the next character you read going to look like? (You already know it is not a digit, otherwise find_digits would have read it. So when find_digits finishes and returns a number, my_char is hopefully going to be one of '+' or '-' or '*' or '(' or something like that. If not it is invalid and you can complain about the equation.) Here again is a list of valid equations:

1+2+3
-9+10
12*-2
5*(2+3)
(2*(1+3))-1

And some invalid ones:

3,7
+
We're #1!

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Heh heh, yeah.

Nowadays people like to call pointers "references" and pretend they're all beautiful. Same bully thing.

I think it is a really good idea to have a clear understanding of what pointers are and how they work, because you will always need them at some point. (Well, unless you're playing with an interpreted language like Tcl, or a functional language like Scheme...) And because they are pretty basic to understanding how a computer actually works...

:)

Duoas 1,025 Postaholic Featured Poster

Beautiful!

Now that you have the 5, what are you going to do with it?

[EDIT] Wait! Er... Your find_digits is using the global variables 'my_file' and 'my_char'. To help you out, I would like you to take that entire

Var
   error   : boolean;
   num1    : integer;
   my_file : text;
   my_char : char;

block and move it so that it is immediately before the BEGIN .

Your program will then not compile. See if you can fix it so that it does (without putting the var block back at the top).

Duoas 1,025 Postaholic Featured Poster

OK, sorry for the double post.

The reason it hasn't complained about "c" is that it is a global variable, which I am trying to get you to avoid using. The same is true of "file1". In all your procedures and functions, you could get rid of the "var c: char" parameter and your program would work fine.

What I would like to see, though, is something like this:

program foo;

procedure ignorespaces( var f: textFile; var c: char );
  begin
  while c = ' ' do read( f, c )
  end;

{ The following variables are 'local' to the main program's block. }
var
  my_file: textFile;
  my_char: char;

begin
  ...
  ignorespaces( my_file, my_char );
  ...
end.

This makes your code more modular and more understandable. The "ignorespaces" function only cares about information given to it. You could use it on any file you want --even multiple files at the same time.

var
  my_file:      textFile;
  my_char:      char;
  another_file: textFile;
  another_char: char;

begin
  ...
  ignorespaces( my_file, my_char );
  ignorespaces( another_file, another_char );
  ...
end.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes, it looks good, except that you aren't returning the value of num.

Notice in "convert" you return the value ord(c) - ord('0') by "assigning it" to the function name: convert := ord(c) - ord('0') In any BP dialect, you can also say: result := ord(c) - ord('0') The "find_digits" function goes through all the trouble of calculating "num", but it fails to say: find_digits := num at the end...

You forgot to remove the "find_digits" all by itself right after the "begin". The next one is correct.

Good job!

[EDIT] Oh yeah, the "ignorespaces" needs to account for the next character the same way:

procedure ignorespaces( var c: char );
  begin
  while c = ' ' do
    read( file1, c )
  end;

All your procedures and functions will have the same issue: they'll have to have a var c: char in the parameter list.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Thanks. Please keep in mind that the OP (and most other readers here) haven't read (nor will they) the R5RS.

The R5RS committee needed a word for a technical thing. They chose poorly (though, considering the circumstances and the technical issues, I don't blame them).

A "procedure" is a very broad term. In most computing contexts that I am aware of, procedures return value by way of side-effect only, whereas functions explicitly return value.

In Scheme, a combination (a lambda), is a function call: local values are bound to an expression which is evaluated for value. That value then replaces the local context. Please keep in mind that this is a functional operation --hence the term functional languages.

Please understand that I'm not being rude. You are very correct. However, you must be careful not to confuse those reading here with those who care about all the technicalities and terminologies specific to functional languages and Scheme in particular.

To be short: in Scheme it is meaningless to talk about the difference between a procedure and a function. But in the minds of programmers everywhere, unfamiliar with Scheme, the difference is in "how do I then get this value to be passed out of the procedure". The answer is, there are no procedures in scheme (or any other functional language). Only functions (or lambdas) that evaluate to (or "return") a new value. You pass a value out by evaluating to that value.

I hope I've …

Duoas 1,025 Postaholic Featured Poster

Your find_digits is good, but it never lets go of "num". find_digits; { What is num? } I would make it a function: function find_digits( var c: char ): integer; Then you can learn num: the_number := find_digits( c ); You also need that var c because c is always the next character read from the file. If you don't have that, then the last character read from file by find_digits will be lost. Make sense?

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

That's because you keep thinking the computer can help you. Computers never help anyone. They're too stupid.

Turn the computer off. Get out some colored paper and some crayons and draw how you (that is, how you, personally) can solve equations like:

1+2+3
-9+10
5*(2+3)
(2*(1+3))-1

(These are ordered by increasing difficulty.) Be sure to nitpick. "First, my eyeball saw '1'. That's a number. Then my eyeball saw a '+'. That's good, because a number needs to be followed by an operator." Etc.

Once you can tell yourself how to solve the problem, then it is time to start thinking in terms of how to make the computer do it. Each step you made might be one or two or three steps the computer will make. Each one of those steps might be made up of even smaller steps.

For example, a big step might be "find the outermost matching parentheses." A smaller step would be something like "find the first '('", and "find the matching ')' [skipping intervening '(' and ')']".

Start thinking your way through this, then when you think you can explain how to do each collection of steps (both big steps and small steps), then post back and I'll help you more.

Duoas 1,025 Postaholic Featured Poster

Can you be less specific?

Duoas 1,025 Postaholic Featured Poster

That won't work. Be careful how you initialize the stream.

If I understand correctly, there are two delimiters you need to worry about: the end of line ('\n') and the colon (':'), where the former is primary. So...

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

...
string entire_line;
string part;

// <open file here>

// for each entire line from the file
while (getline( file, entire_line )) {

  // get yerself -another- stream to read,
  // containing only the line to tokenize.
  stringstream ss( entire_line );

  // for each token in the line (delimited by :)
  while (getline( ss, part ))
    cout << "Got me a part of the line: " << part << endl;

  // (The stringstream dies here, a new one is created for
  // the next line of the file on the next iteration of the loop)
  }

If you want to reuse your stringstream (my loop uses a different stringstream each iteration) you'll have to ss.clear(); it and ss.str( new_string ); reinitialize it (set the new string to use).

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You are both mixing between the pointer and the pointee. CPoint foo; is an actual CPoint. It exists. CPoint *foo; is a pointer to a CPoint. So far, no CPoint actually exists. CPoint **foo; is a pointer to a pointer to a CPoint. So far, neither a "pointer to a CPoint" nor any Cpoint exists.

So, Lerner started out right: you need to create the things that exist one step at a time.

CPoint **points;

// Create 200 "pointers to CPoint"
points = new CPoint*[ 200 ];
// (So far, no CPoints exist)

// Create 200 CPoints
for (int i = 0; i < 200; i++)
  points[ i ] = new CPoint;
// (Now you have 200 pointers to 200 CPoints)

points[ 42 ]->Move();  // Move the 43rd planet

I'm still not sure I understand exactly what you are trying to do, or even why you are dinking around with pointers in C++ (just use a vector or a deque or a list), but I...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I'm sorry. My brain must have failed me when I posted last. I thought you were trying to interface with a C function.

What language are you trying to use?