Rashakil Fol 978 Super Senior Demiposter Team Colleague

That's extremely dumb. Compiler errors are extremely rare, and you're not going to set one off just by using gets.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

It's not your compiler, it's you. Also, that file you linked doesn't use fgets.

Instead of using gets, you should use fgets.

But really you should use std::string functions.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Also, it seems to me like 'every' and 'tween' are rather kludgy features.

I'll post an example of what I would consider to be a more comfortable C++ parser generator at this level of scope later tonight.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Thats a very good point. The problem is that wordforms currently don't have a good way to describe having multiple choices (which is why the whitespace example is so verbose). Choice blocks are verbose however. Do you have an idea of what better syntax would look like?

I'm not sure if you misinterpreted me. I was saying that having multiple choice blocks in a row is unnecessary -- instead of having consecutive blocks for /[0-9]{3}/, / [0-9]{3}/, and /-[0-9]{4}/, the way you have with your first telephone example, you could just have separate named parse blocks for those three things.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

How is it broken? It looks perfectly valid to me, and it works. What do you suggest I do if gets and fgets crash my program?

Your code has no way of checking if it is overflowing the buffer which has been passed into it. You shouldn't use gets for the same reason. Paste an example where fgets is behaving buggily and I can take a look.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Note that I'm not saying any good things about your project not because they aren't there, but because it just doesn't suit my disposition.

Now, if you're going to continue with C++, you should spend some time learning C++. You write C++ like a C programmer. For starters, why are you using malloc? You're writing C++. Using "malloc" or "realloc" in C++ is a huge mistake. You can't just take any old array of type T and call realloc on it. Why not: Because realloc does a raw memory copy, instead of calling the objects' copy constructors. Your 'T' might be a datatype that looks like this:

class foo {
  int[10] nums;
  int* current;
 public:
  foo() { current = nums; }
  foo(const foo& other) {
    for (int i = 0; i < 10; ++i)
      nums[i] = other.nums[i];
    current = nums + (other.current - other.nums);
  }
  void add(int n) {
    if (current < nums + 10)
      *current++ = n;
  }
  void get(int i) { return nums[i]; }
};

This class's implementation depends on its location -- if you just copy its raw memory, your class will behave erratically.

The same goes for malloc: a = (T*)malloc(n*sizeof(T)); is just horrible -- your T's will never get constructed!

#define ITER1(x)		for(int n1=0; n1<x; n1++)
#define ITER2(x,y)		for(int n1=0; n1<x; n1++) \
							for(int n2=0; n2<y; n2++)

These macros are unsafe and insane.

[[Edit:
They are unsafe because ITER1(f()) will call f() each time through -- and the user …

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Also, I don't see the reason to have two mechanisms for concatenating parsers: successive choice blocks and wordforms. They do the same thing, so they add needless redundancy.

Your 'anychar[]' and 'anyindex' features seem unnecessary, almost silly. To say you want a string of characters that satisfy a given predicate, you already have that feature.

Rashakil Fol 978 Super Senior Demiposter Team Colleague
void getline(char* line)  
    {   int n=0;
        while((line[n]=getchar()) != '\n')
        { n++; }
        line[n]=0;
    }

You shouldn't use broken code examples.

parse ws
[   anychar[] Wo
    anyindex an
->  Wo   Wo[ Wo[an]==' ' || Wo[an]=='\t' || Wo[an]=='\n' ]
    [ return true; ]
]

This is _extremely_ verbose for something that just parses whitespace. I'm pretty sure that's simpler to do in other parser generators, and more readable. For example, with ANTLR (and I might be buggy here, I haven't seen ANTLR myself except on IRC channels), you would just see something like

WS : (' '|'\t'|'\f'|'\n'|'\r')+ { $channel=HIDDEN; };

For a parser combinator library like Parsec, it would just be

ws = skipMany1 (satisfy isSpace)
Rashakil Fol 978 Super Senior Demiposter Team Colleague

> How exactly are you expecting to talk to the system or any peripherals without making a call to the OS?

On some operating systems and some devices, you can do just that.

Freaky_Chris commented: lmao +2
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I think they're boring, but you can do what you want.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Nina 4 Ever, you should ask in the C++ forum (since you're talking about writing C++ code).

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Lex and yacc are obsolete (because they use C); use something more like ANTLR... for parsing. But this is just in reply to ithelp's post, obviously it has nothing to do with your problem.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

This is probably the best-written project idea request I've seen on this forum.

The answer, of course, is to figure it out yourself :-)

A good way to think of an idea is to just think of bad ideas. Just make a list of ideas that you don't want to do -- that will get you into the frame of mind where you can think of something that you personally will enjoy.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

So, in simple terms, what is extreme programming all about?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Date of birth on a job portal? Are you mad?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

What are you talking about; what's BPO?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I'll do it for $500.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You can figure out your first problem just by looking at your results. You're not printing the last 1 of each row. Why? Well, you're stopping too early in your loop that prints out the row's numbers.

For your second problem, if you temporarily added a few cout statements that showed the numbers you're adding, you'd see your problem very quickly.

You might not have to go through this effort -- I'm sure some shmuck will come along to tell you exactly what's wrong with your code.

cherryteresa commented: Guided me in the right direction. +1
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Dynamic typing vs. crappy static typing vs. good static typing; concurrency.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

A few points: Sorry to preach...

You allocate 33971 lists!! Much better is to use a map.
std::map<int,std::string>

If you want to record clashes then us a multimap.

Are you joking? He's implementing a hash table.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

message_to_network should already be a function that waits for a new message to reach the socket. I'm guessing about its implementation, but you should just need to call that function -- it will return as soon as the message arrives, or when the connection times out. Obviously, it makes no sense to close the socket.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Who are these people who've put you through such a ridiculous assignment? Off with their heads! You should be writing code!

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Why not put your music degree to work in the IT field. I should think you could get a job at one of the big game houses providing and/or writing music for the games.

It's probably quite hard to get a job like that. And the idea that such a job would have any meaningful relation to the IT field is laughable.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You haven't told us how many words each of the two files have.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

This is the stupidest use of operator++ I've ever seen.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

ummm....lol. What a rediculous objective. Is this to be console based? No graphics whatsoever? If it is console based, I'd say that the contest is much too easy and find it hard to believe that an award is really being offered.

Then why don't you cry about it? Oh wait, you did.

(Graphics??? WTF are you thinking?)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Yes. One easy way is to use two maps, one map<int, double*> and one map<double*, int>. You need to make sure that you only have one index per color, though. If you want to be able to have a color appearing at multiple indices, use a multimap<double*, int> instead of a map<double, int>.

Rashakil Fol 978 Super Senior Demiposter Team Colleague
int getUnique() {
  static int n = 0;
  return ++n;
}

This function is not multithreading safe.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

It seems that the boost libraries use .hpp.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You can use the Distinct extension method.

public string[] GetUniqueStrings(string[] input) {
    return input.Distinct().ToArray();
}

You can do the same for a List<string> , only use ToList() instead of ToArray() .

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Not unless you explain what "H" or "HD" or "WSO" or "[;g(n-1)]" are supposed to me.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Yes, there are.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Not software development.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Your second method is broken -- you forgot isdigit. Your third method is not radical.

Negative values will fail when a lookup table is used to implement the function -- they point in memory outside the lookup table.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Ya think? Looking at your code, how could you expect it to do anything different? I don't see any attempt to maintain a board's state, and your program does not even deserve to be called an attempt at a checkers program; except upon the rare click, it just calls GamePaint over and over again, drawing the starting position of a checkers board.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

People here get really grumpy when folks ask about final project ideas, because it happens so often.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I have never heard of "SAP," other than as the name of a company whose U.S. headquarters are in Newtown Square, PA, so I would just ignore whatever punjabivirsa3 is trying to say.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

But that wouldn't give the right result. It would give 0.50 if the number of days was 25. But on the 25th day, the person would earn 167772.16.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Get a better compiler. And post a real code example.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

No no no no no don't do that, then you have no hope of disabling RTTI :D. There are other, more serious downsides, like the fact that if you ever change your code to include another subclass, all your code that uses typeid becomes broken.

There is something known as the "visitor" pattern, which is designed to get around this issue. Unfortunately, C++ has horribly syntax and it's really more tolerable in C# and Java. But you get used to it.

It works like this:

class FastConcat {
 public:
  virtual void Visit(FastConcatVisitor& visitor) = 0;
};

class Leaf {
 public:
  std::string* s;
  void Visit(FastConcatVisitor& visitor) {
    visitor.VisitLeaf(*this);
  }
};

class Branch {
 public:
  FastConcat* left;
  FastConcat* right;
  void Visit(FastConcatVisitor& visitor) {
    visitor.VisitBranch(*this);
  }
};

class FastConcatVisitor {
 public:
  void VisitLeaf(Leaf& leaf) = 0;
  void VisitBranch(Branch& branch) = 0;
};

void sumToString(FastConcat& tree, std::string& builder) {
  SumHelper helper(&builder);
  tree.Visit(helper);
}

class SumHelper : public FastConcatVisitor {
  std::string* accumulator;
 public:
  SumHelper(std::string* acc) : accumulator(acc) { }
  void VisitLeaf(Leaf& leaf) {
    *accumulator += leaf.s;
  }
  void VisitBranch(Branch& branch) {
    branch.left->Visit(this);
    branch.right->Visit(this);
  }
};

If you wanted to add a third kind of FastConcat string, you could do so, and then add a third unimplemented function to the visitor. Then you'd get a bunch of compilation errors, telling you all the places you need to fix your code (where you only implement two of the visitor base class's three abstract methods).

Rashakil Fol 978 Super Senior Demiposter Team Colleague

If you think your code produces the correct results on the inputs you've tried, maybe you could say what your code does to us, step by step. We could then see where you have a mistaken understanding.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Don't follow Ancient Dragon's advice; it's horrible design.

What do you mean exactly by "single instance class"? Why don't you pass the instance by reference?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

This is a stupid question. You should write small sample programs to verify your understanding of things like this.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

How about you go through your code by hand with some sample inputs and follow what it is doing. Then you'll see why your code doesn't work.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I would like to compute the main() alone of the file.

It's hard to understand what you mean, due to your difficulties with English. Could you try rewording this sentence? That might make your desire more clear.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Are you having a problem with this homework assignment? I recommend figuring out what information you need to help yourself and then operating on that.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

You don't need to quote the entire message.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Initialize the salary at 1 and, each time through some look that runs 'days' times, double it.

Or you could just use 1 << (n - 1) to compute the amount paid on the nth day, or (1 << n) - 1 will give you the cumulative amount paid after n days.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Yes, Minix.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Why would you want to limit the number of buckets?