Rashakil Fol 978 Super Senior Demiposter Team Colleague

No, it's compiler dependent. Compilers are specific to the architecture they're compiling for. And you're wrong about the size of a long.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

> Is the code expected to be HW/compiler independent ?
Standard C++ is always compiler independent.

Uh, no, for example, my code is standard C++, but it assumes 32 bit unsigned longs.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

That's what if statements are for.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

FFS. All we need is a grassroots rebellion based on government nonintervention in the energy market. The reason fuel is so expensive (haha, it's actually absurdly cheap) is that demand is up and supply is down. And demand will continue to rise dramatically, and supply will continue to be unpredictable. If you want economically efficient fuels, vote for some free market person. Heck, even vote for a free market person that believes in welfare, just somebody that doesn't believe in protectionism and subsidies.

Then you'll get energy as cheap as it can get. And you'll find out which is most economically efficient. Without having to think about it!

If you want to get really excited, add taxes on top of that to account for damage to the environment. You can never calculate those precisely (and they'll probably be calculated very imprecisely).

And solar and wind energy suck. Or you'd be seeing more of it, nyes?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I am serious. There are three cube roots of -2 -- three values x for which x^3 = -2. I'm talking about complex numbers. Which one should be returned? The negative one? Or the two others which are sixty degree rotations of that? What about the sqrt(9999999999999999)/300000000 power of -2? What's that? You've got an irrational power that's really close to to 1/3. All of the sudden, you have countably infinite values x for which x ^ (300000000/sqrt(9999999999999999)) = -2. Which one do you choose? What about the pow(-2,1.0/3.0)? Remember that 1.0/3.0 is not one third. The floating point approximation will exactly represent some number in reduced form that has a denominator that is a power of two, greater than one. That means all the roots are not real.

If you want to approximate the function that's the inverse of the function f, where f(x) = x^3, you can't just use pow. You need to take the absolute value to the 1.0/3.0, and then adjust the sign.

If you were to ask me what pow(-2,1/3) should return, if it could return complex numbers, I'd say it should return the value equivalent to pow(2,1/3) * cos(pi/3) + i * pow(2,1/3) * sin(pi/3).

Rashakil Fol 978 Super Senior Demiposter Team Colleague

The cube root of -2 isn't a real number. So you're not going to get a real answer.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Actually, there was one revelation, involving my very first negative rep, from back when I was a noob on this forum.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I have to admit, the opening up of who gave what rep provided no revelations for me.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Oh man, doubleplus retarded. Here's a version that uses the right variable names...

unsigned long extract_digits (unsigned long x, size_t n, size_t i) {
  static const unsigned long tenpows[]
    = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

  size_t len;
  if (x < 1000) {
    len = 1 + (x >= 10) + (x >= 100);
  }
  else {
    if (x < 1000000) {
      len = 4 + (x >= 10000) + (x >= 100000);
    }
    else {
      len = 7 + (x >= 10000000) + (x >= 100000000);
    }
  }

  x = x / (tenpows[len - i - n]);

  return (x % tenpows[n]);
}
Rashakil Fol 978 Super Senior Demiposter Team Colleague

If it's harsh then that means it's right.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Well you're already living in a cage, which, dietary anomalies aside, is already less than 6' by 8'.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I can't remember such levels of interpersonal drama ever on this forum, before christina came here.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Haskell 98: The type system makes it impossible to shoot yourself in the foot.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Aw, c'mon. You can do the intermediate level. Please? :P

F the intermediate level. I'm skipping to "expert". Or at least giving people ideas for the expert level.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I'm assuming valid input.

~s.o.s~ commented: Programmers don't assume ;-) -4
Duki commented: Yep +0
WolfPack commented: Let's keep the C/C++ forum rep meaningful shall we? Let the non-geeks polute the geeks lounge rep. +8
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Nevermind. Disable color. Remove fonts, and sizes and fonts and colors [again] [[oh, my]].

Then get rid of smilies and indentation, and bulleted listings, and quotes, and code tags, and hyperlinks. And what not. Keep thinning the herd until you've gone too far. Then turn back. I'm leaving now.

A statement which comes from somebody who hasn't posted outside the coffee house in three months.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Okay. Here's a version that should fix that break. It's passed zero test cases :-)

unsigned long extract_digits (unsigned long x, size_t n, size_t i) {
  static const unsigned long tenpows[]
    = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

  size_t len;
  if (x < 1000) {
    len = 1 + (len >= 10) + (len >= 100);
  }
  else {
    if (x < 1000000) {
      len = 4 + (len >= 10000) + (len >= 100000);
    }
    else {
      len = 7 + (len >= 10000000) + (len >= 100000000);
    }
  }

  x = x / (tenpows[len - i - n]);
  
  return (x % tenpows[n]);
}
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Well, take the average conspiracy theory nut that thinks that 9/11 didn't happen or that the moon landing didn't happen. Then replace 9/11 or "moon landing" with "The Holocaust."

Rashakil Fol 978 Super Senior Demiposter Team Colleague

We don't need a change in anything. Oil and gas prices are not an economic problem situation.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Don't think you can trick us into doing your homework for you! This is the oldest one in the book!

And here's a lame version that assumes reasonable input, has passed only one test case, and assumes 32-bit longs.

unsigned long extract_digits (unsigned long x, size_t n, size_t i) {
  static const unsigned long tenpows[]
    = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

  size_t len;
  if (x < 1000) {
    len = 1 + (len >= 10) + (len >= 100);
  }
  else {
    if (x < 1000000) {
      len = 4 + (len >= 10000) + (len >= 100000);
    }
    else {
      len = 7 + (len >= 10000000) + (len >= 100000000);
    }
  }

  x = x % (tenpows[len - i]);
  
  return (x / tenpows[len - i - n]);
}
WolfPack commented: ha ha ha. +7
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I just gave you a bad rep because you down repped me despite the thread topic. You don't like quotations from Katamari Damacy? I'll give a good rep the next time I find a good post of yours after I can rep you again. And Wolfpack came a year ago and started typing Japanese, so how are we supposed to reply to that?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Na!

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Na

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Ba

christina>you commented: /? -2
WolfPack commented: Equalizer +7
arjunsasidharan commented: :) +2
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Comp Sci I

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Relax. You'll do fine. If you feel nervous about the exam, practice writing programs or functions that solve particular problems entirely on paper. Type them into the computer and compile them and see how they fail. Based on your mistakes, take note of what modes of thinking should be avoided.

Also, don't use an IDE; use a text editor (a good one that at least indents your code to the right number of spaces, not Notepad). You'll be more comfortable that way, since IDEs train you to doubt yourself. Then you can use an IDE later if it's more convenient.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

First, the program communicates with the operating system differently. To perform input and output, it must talk to the OS with a system call, using a particular protocol, and they use different protocols. Second, the libraries are different. Linux programs expect libraries with functions like printf and whatnot to be in particular places; Windows programs expect them somewhere else. Third, the filesystem and arrangement of where things are stored is different. Fourth, the executable file format is different. The Linux procedure which launches programs expects executable files to be in a particular format (or one of a set of formats?). The .exe file format(s?) is (are?) different. The general scheme of how GUI output is performed is different. The notion of processes is different. And on and on and on.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

The easiest way is to make a C++ string and use its concatenation operator (which happens to be the plus operator). Use the c_str method to get the C-style string that's similar to the C++ string you've concatenated that the system function needs.

#include <stdlib.h>
#include <iostream>
#include <string>

using namespace std;


int main(){

  string directory;

  cout << "enter directory name: ";
  cin >> directory;
  system("ls -l");
  system(("mkdir " + directory).c_str());
  system(("mkisofs -J -o filename.iso " + directory).c_str());

  return 0;

}
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I think ultimately the trick to pull off is to bend spacetime over on itself

While we're at it, let's run the engine with sunspots! Accelerate using negative gravity! Reroute power from the deflectors! Spiderwalk along lines of magnetism, for extra efficiency!

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Store the array alongside a 'multiplier value' that you multiply the elements of the array by when reading them (and divide by when writing...). Then have MultiplyAll simply change the multiplier value.

Also, keep a counter and increment it with every ZeroAll call. Store with each element in the array a value that tells what the counter's increment was the last time you wrote to it. If the ZeroAll counter is greater than the counter alongside your value, then treat the value as if it were zero.

~s.o.s~ commented: Good one.. ;-) +19
iamthwee commented: To counterbalance your star I'm sending you this. -2
Aia commented: I don't like your avatar, but still like you. - Aia :) +1
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Your get_letter grade function has a space in its name, and the implementation doesn't return anything.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Generally speaking, it's whichever algorithm takes the most advantage of hardware. For example, people pretend that bucket sort takes linear time, but it really takes O((n+k) log k) time, where k is the number of distinct elements. They pretend it takes linear time because for values of n and k that are less than a billion, the log(k) factor fits inside one machine code instruction. The reason quicksort is faster than heapsort is that it takes advantage of the cache. Or it's that heapsort doesn't. Similarly, you'll find that insertion sort goes much faster for sorting a deck of cards than merge sort does, but quicksort still comes out on top.

Postman's sort is available online; find it yourself.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Stalin doesn't deserve credit for stopping Hitler; it's the millions of Soviet soldiers who deserve the credit. All Stalin deserves credit for is for playing the following text adventure game.

Hitler is attacking you!
  1. Defend yourself.
  2. Send giant bunnies.
  3. Invent Tetris.
Your Choice: [b]1[/b]

Hitler loses!  HP/MP restored!
But you're still hungry.
christina>you commented: haha, I like the little attachment there. +8
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Are we playing Buzzword Bingo?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

- I don't understand the question.
- The expression (&T) returns a value of type nodeptr**, when T is of type nodeptr*, but insert expects an argument of type nodeptr*.
- Case 10 doesn't change the value of T, so the nodeptr T still points at the same place in memory as it pointed before. Technically, that memory is freed, and it could be overwritten when another block of memory is allocated and written over. However, until that happens, the values in memory are still there. Perhaps you should make cleartree a function with the declaration void cleartree(nodeptr* T) , so that it can set *T = NULL;

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Um, plants are too. Are plants animals? No.

Neither are fungi. Animals are in the kingdom Animalia.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

1. The expression "Literal string" is a cute way of writing a memory address that points to to the front of an array of bytes, somewhere, whose contents are "Literal string". Except when initializing an array.

2. Both of those produce equivalent behavior, nyes?

3. Your program doesn't do anything; why would the compiler treat it any differently from void main() { } ? And main is supposed to return an integer.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Well, your rep marks were all the same light green color, to me, when you first mentioned and posted the screenshot of it. But now they're darker.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Okay. Now I'm seeing your rep bar get darker, too.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

The only way to stop animal cruelty is animal extinction.

Anyway, the line of ethics is going to get pretty trippy in the next century.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

S.O.S. I see it in your screenshot, but I don't see in on my computer. It's not your eyes... But speaking of revelations, rereading the religion thread has been fun.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

He could just cout the string itself, so I take it this is just a test program for another project.

~s.o.s~ commented: Heh, that was really interesting. +18
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Your string's not null-terminated, unless you're lucky. In Dev-C++, it turns out that a zero was already there at the end of the string 'line'. In VC++'s executable, that turned out not to be the case.

You need to use

line = new char[length + 1];
strLine.copy(line,length);
line[length] = '\0';

in place of what you have there.

What you're doing is setting the characters to zero and then overwriting all the zeros you wrote, which is just pointless. You need a zero _after_ the C-style string, to delimit its end, so you need to allocate one extra byte for that zero and then set it to zero.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

I'm from America, but I've been in Canada since this place changed its smileys.

John A commented: :-) +11
Rashakil Fol 978 Super Senior Demiposter Team Colleague

There are two ways to improve your skill and knowledge. One is to learn other interesting programming languages (such as Scheme, Python, Perl, Haskell, or Factor, since this will improve your C++ skill), and the other is to write more programs. The latter is essential, and the former is important.

I'd say the best way is to fiddle fiddle fiddle. I can't recommend specific starting points until you say what you mean by "software programming". You mean GUI-based? Depends on the OS. Get a copy of Visual Studio and start playing, making _really_ simple things that you know works, and fiddling things out. Heck, I recommend going into GUI programming with C# instead of C++, if you're going the Windows route.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

The easiest way would be to fork off a call to wget and pipe back its output.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Then that's not the case, since RECT and POINT both use LONGs. Maybe you should look closely at the behavior of Get_Mouse() and see what it outputs.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

It seems that you're using an unsigned integer to represent your coordinates. When you decrement an unsigned integer, such as 0, instead of getting -1, you get the highest possible value the integer can represent.

In fact, if you're getting 32 thousand, you're probably getting errors related to the comparison of integers -- you're probably representing your paddle coordinates with unsigned integers while your mouse coordinates are signed, or maybe the other way around. I'm guessing your paddle coordinates are rolling over from 0 to 65535 and then getting decremented 32 thousand times ... or something like that.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Not to mention that his very own example is still unsafe!

Rashakil Fol 978 Super Senior Demiposter Team Colleague

That's a... dun dun dun

ONE MEGABYTE FILE!!!

That's not relatively small. Especially considering there's no reason not to post a PNG.

But wow. I've never seen the reps other people give you. Ha ha ha.

As for the topic of killing people, who else do you have on your death list?