sepp2k 378 Practically a Master Poster

You're trying to apply the prefix ++ operator to the result of the expression a++. The result of a++ is a temporary value and thus not assignable, i.e. it is not an lvalue. Since you're only allowed to use ++ on lvalues, you get the error that you get.

Somewhat interesting side note: The result of a++ is an rvalue in both C and C++. However the result of ++a is an lvalue in C++, but not in C. So if you changed your code to say (++a)++, your code would work in C++, but not in C.

sepp2k 378 Practically a Master Poster

The pearsonr function returns a tuple containing two values. The [0] selects the first of those two values.

sepp2k 378 Practically a Master Poster

I'm not sure I understand your question. The values for j and k will not affect the size of the resulting arrays. If a is an array of size n*m then a[ ..., j ] is an array of size n, no matter what the value of j is.

Or more generally: a[ ..., j ].shape == a.shape[ : -1 ] for all multi-dimensional arrays a and all valid indices j.

sepp2k 378 Practically a Master Poster

If a is an n-dimensional numpy array a[..., j] will return an (n-1)-dimensional numpy array where each innermost subarray is replaced by its jth element. So for example if a is 2-dimensional, a[..., j] will be a 1-dimensional array containing the jth column of each row.

Nothing in Python, looks like pseudo code.

Actually, ... is perfectly valid Python syntax - it's just not used anywhere except by numpy and scipy.

sepp2k 378 Practically a Master Poster

You call Time.sleep once before the loop. Inside the loop you keep making attacks without calling Time.sleep. For that reason your program will pause once before the loop. Inside the loop it will keep making attacks without pausing.

sepp2k 378 Practically a Master Poster

The reason is that it might not read in the way you want.

What do you mean by that? SomeString.split('\t') will quite certainly work as expected if the given string actually contains tabs.

"John Doe\t15000\t34\tSeatle".Split('\t') returns { "John Doe", "15000", "34", "Seatle" } as expected.

 // The result will be ["John", "Doe", "15000", "34", "Seatle"]

I don't think that's the Result the OP wants. He wants to split by tabs, not spaces, and I don't think there's supposed to be a tab between "John" and "Doe" - just a regular space. In other words I assume the intended result is {"John Doe", "15000", "34", "Seatle"} and there's no way to get this result reliably if the string does not actually contain tabs (because there's no way to distinguish a space (or sequence of spaces) that was originally supposed to be a tab from a space that's just a space).

sepp2k 378 Practically a Master Poster

So in order to display data onto the screen, data must go into the RAM first?

Generally yes. But as I said that doesn't mean that the whole file must be in memory at once. That wouldn't even be possible in this case.

And if the RAM is out of space, then it stores temporary data onto the hard drive as swap files?

Yes, but again that's not what's happening in this case. Trying to read the whole hard drive into memory at once would crash the program - swap file or not.

Since it is storing data onto the hard drive, is there a chance that it will overwrite old data(such as deleted files)?

Yes, writing new things to a hard drive always has the chance of overwriting deleted files (but again note that you can't read the whole hard drive into memory at once and reading only parts of it at a time will likely not involve any swapping).

And when data is being stored from RAM as a swap file, is the data always stored in the same sector(s) on the hard drive, or is the address location dynamic as in it might not always be in the same location?

I'd assume it would be placed just like any other file. But I really don't know anything about how Windows handles swap files.

I'm trying to create a data recovery program and i'm worried that there will be …

krayzeeben commented: very informative +0
sepp2k 378 Practically a Master Poster

Depending on your operating system data will be moved from your RAM into a swap file or partition once your RAM is full.

That said there is no way that your hex editor reads your whole hard drive into memory before displaying it. Not only would reading such large amount of data take an awful lot of time, there's no way you could fit into all into memory - even with swap files (there is usually a maximum size for swap files and even if there weren't, it would be limited by available disk space).

As you said, only a small portion of the data is displayed at any given time, so it'd be easy for the editor to only read a small portion of the data and then load further portions (and possibly unload old portions) as you scroll down.

sepp2k 378 Practically a Master Poster

getValues is a member function of the EmployeeForm class. That class does not have a member called empList.

empList is a member of the Payroll class, so you can only access it through a Payroll object.

sepp2k 378 Practically a Master Poster

As someone who knows very little of conio.h, could you explain how cprintf, cscanf, cgets, cputs etc. behave differently than the standard functions of the same name minus the "c" at the beginning?

sepp2k 378 Practically a Master Poster

Yes, they're the same.

It only matters whether the const appears before or after the *. If it appears before the * it does not matter whether it appears before or after the typename.

sepp2k 378 Practically a Master Poster

Are you sure that the file actually contains tabs? It looks like the line simply contains multiple spaces, not tabs.

sepp2k 378 Practically a Master Poster

However my advice is not to define objects with a del() method because they can create uncollectable objects if they are part of a reference cycle

Yes, but since his robots don't contain references to each other, that can't happen here.

Also there is no guarantee that the del() method will be called at all, which is another reason not to use this method.

It's only not guarantued if the object is still alive at the end of the program, in which case it wouldn't matter for this use-case since there's no way to callRobot.howMany() after the program ended.

sepp2k 378 Practically a Master Poster

first you have not proved the values are within specs asked for

Usually if the assignment says that a variable will be in a given range, I'd think that means that you can assume it will be, not that you have to verify it.

second your use of double seems you automatic use it but don't understand its implications .... because you failed to make the value i a doubl

I think it's safe to assume that the values given for n and k (and thus the possible values for i) will be within the range of an int (if they're not, you'll be waiting a long time for the function to return) while the result might not be.

if ( x > 1 )
    return x * fact( x - 1 )
else
    return double(1)

Please don't recommend using recursion to calculate the factorial. It's less efficient than using a loop and can cause a stack overflow for large arguments.

sepp2k 378 Practically a Master Poster

This is probably not the solution your instructors are looking for. I imagine your instructors are looking for a solution where you caclulate n!/k! without calculating n!.

Note that if you expand n!/k!, it will look like this:

1 * 2 * ... * n
--------------------------
1 * 2 * ... * n *  ... * k

See how the 1 * 2 * ... * n part repeats in both the numerator and the denominator? If you were to calculate this by hand, you wouldn't calculate that part, right? You'd just cancel it out and only calculate the part that doesn't repeat. I imagine your program is suppsed to do the same.

That will not only lead to a better running time, but also to less rounding errors for large n and k.

sepp2k 378 Practically a Master Poster

You've defined gem to take 2 arguments, but you're calling it without any arguments.

You should also forward-declare gem or define it before the main function.

sepp2k 378 Practically a Master Poster

i mean why scanf is waiting for input ? why is it expecting a character ?

Because, as has been explained repeatedly now, a white space in scanf's format string means "consume any whitespace characters until you find the next non-whitespace character". Why does it mean that? Because the C standard says that that's what it means.

new line is a white space or non-white space character ?

The newline character is a whitespace character. For more information on what is and isn't a whitespace character see the documentation of the isspace function.

sepp2k 378 Practically a Master Poster

Lotta hate here

Calling statements like "that's a bad idea" hateful is a tad dramatic, don't you think?

In engineering we once got things done .. now we gotta be sure we don't offend the immature and neurotic.

Nobody's offended (or at least I'm not - I suppose I can't really speak for the other people participating in the thread (though I've surely seen no indication that they're offended)). We're just explaining why, in our estimation, the macros suggested by the OP are bad ideas.

If the worry that you might get (mostly) constructive feedback on your code is what's keeping you from getting things done these days, then ... honestly I don't really know how to finish this sentence.

sepp2k 378 Practically a Master Poster

Okay, I've looked on your code more closely. On line 7 you've assigned a string to a double. This will convert the string to a double using your current locale. So on your system this causes the value of DS to become fifty thousand, not 50.

If you want to disregard locale settings, you should not be doing any implicit conversions from string to double or vice-versa. Always use explicit conversions, in which you explicitly specify how you want to format the numbers. If that's too annoying, you might want to consider changing the locale for your program (which I might have suggested before in this thread).

If you remove the quotes from line 7 and remove lines 23 and 24, your code should work (at least with regards to how the result of dbldkstring is formatted - InvoerStart and InvoerEind will still be converted using your current locale).

sepp2k 378 Practically a Master Poster

According to MSDN the last argument to FormatNumber tells it whether or not to use a thousands separator. If you leave out the argument (which you did), it uses the current locale's default. So if you don't want to change the current locale, you should pass TriState.False as the last argument.

Edit: Shouldn't the second argument to FormatNumber be an integer?

sepp2k 378 Practically a Master Poster

Since pointer holds the address of the value and addresss is always integer so size of pointer is size of integer.

That's utterly and completely wrong. sizeof(int) != sizeof(void*) on all 64-bit platforms that I know.

sepp2k 378 Practically a Master Poster

Again, use a locale that formats the numbers in the way you want them to be formatted.

Also: It shows the result as "3.000.000", not "3.000,000"? How did you get that to happen? You didn't just multiply the result by 1000, did you?

sepp2k 378 Practically a Master Poster

Also you need to forward-declare your factorial function or define it before the main function.

sepp2k 378 Practically a Master Poster

250.000 - 50.000 = 249950.

Does your system by any chance use a locale where . is used as a thousands separator and , as the decimal point? Because if so, the users should either input the numbers in a format compatible with the current locale (i.e. use , instead of .) or you should explicitly use a different locale when converting the string to a number.

sepp2k 378 Practically a Master Poster

You're never actually compiling the code. You need to call make to create perl and the other binaries you're trying to copy.

sepp2k 378 Practically a Master Poster

According to google¹ those error codes mean "missing token", "missing type specifier" and "unexpected token" respectively. So it sounds like you have some sort of syntax error somewhere in your code.

¹ Next time please post the error message, not the error code, so I don't have to google it. Thank you.

sepp2k 378 Practically a Master Poster

Yes, you're right - it's not correct. For one thing, as you said, the number of moves is wrong.

Further when I enter 3 as the number of disks, it tells me that after the first step there will be 1 disk on the source pile, 2 disks on the auxilary pile and 1 disk on the target pile, making a total of 4 disks. So where did the 4th disk come from? And in the second to last step there's only two disks. Obviously in a correct program there'd be the same number of disks at every step.

Also the program never prints which moves it actually performs, leaving you to guess that from the number of disks on each pile (which might be okay if those numbers weren't total nonsense).

So yes, your solution is wrong. I don't think there is a correct solution that doesn't use recursion or an explicit stack (or some encoding thereof).

sepp2k 378 Practically a Master Poster

You need to post a self-contained code-sample that compiles, runs and demonstrates your problem. I can't help you just from looking at those 2 lines of code.

sepp2k 378 Practically a Master Poster

On the end of that line, right before the &&, you have a closing parenthesis. There is no opening parenthesis corresponding to this closing parenthesis anywhere in your script. So you get a syntax error.

sepp2k 378 Practically a Master Poster

Dereferencing a pointer does not just read the byte that the pointer directly points to - it also reads the subsequent bytes depending on how large the pointed-to data type is. So if ptr is a variable of type T* that points to the address 12feac and sizeof(T) is 4, then writing *ptr will read the bytes 12feac, 12fead, feae and 12feaf. So everything's fine.

sepp2k 378 Practically a Master Poster

In this case, replacing the &&s with ||s (i.e. "keep running while at least one of the HullShip variables is greater than 0) would have worked too.

sepp2k 378 Practically a Master Poster

If you'd post your code, we could tell you whether your problem is with your code or your setup.

sepp2k 378 Practically a Master Poster

Generally you should not need to manually download any RPMs. Most applications you want to install will be available in the official repositories and can be installed automatically. MySQL definitely is.

To install the MySQL client and server either select "Add/Remove Software" from the Applications menu and then search for and install mysql and mysql-server or execute "yum install mysql-server mysql" on the command line (with root privileges).

sepp2k 378 Practically a Master Poster

The executable created by lex does not take any command line arguments and if you give it any, it will silently ignore them. It reads its input from stdin and writes its output to stdout. So as L7Sqr said, it doesn't do anything because it's waiting for you to enter some input.

If you want to use your lexer on your myname.txt, you should pipe the contents of the file into your lexer using input redirection, i.e. ./a.out < myname.txt.

sepp2k 378 Practically a Master Poster

The same amount of bytes as there are in all other types of pointers (except possibly function pointers, which might take up a different amount on some platforms). How many that are depends on the platform.

You can find out how many bytes are in an int pointer on your platform by doing sizeof(int*) (or sizeof(void*) - as I said it's going to be the same for all non-function pointers).

Usually it would be 4 bytes on a 32-bit platform and 8 bytes on a 64-bit platform (or more generally n/8 bytes on an n-bit platform).

sepp2k 378 Practically a Master Poster

You cannot end the format string with \n

Well, you can. It just means that scanf won't return until the user has entered another token. (Not that I could imagine a scenario where that's ever useful).

</pedantry>

sepp2k 378 Practically a Master Poster

I don't know anything about Dwarf Fortress, but it's not possible for a terminal application to change the font used by the terminal (using curses or otherwise). So if Dwarf Fortress does that, it must be creating its own window, not running in the terminal.

sepp2k 378 Practically a Master Poster

A whitespace character (including \n) in the format string will cause scanf to discard any whitespace in the input stream upto the next token. If a whitespace character is the last character in the format string that means that the user must already enter the next token, so that scanf knows upto where it needs to discard whitespace.

Genereally you simply don't want to have whitespace characters at the end of your format string.

sepp2k 378 Practically a Master Poster

What does using str on the result of raw_input accomplish? It's already a string.

sepp2k 378 Practically a Master Poster

Its not that simple

What was that in reply to? What's not how simple? You're not saying, that floats are not stored on the stack, are you (nothing in the linked article would support that of course, but since your post came directly after mine, it kinda sounds like that might be what you're saying)?

sepp2k 378 Practically a Master Poster

The how is already sufficiently answered in the article linked in my first post. As to where: If it's a local variable, it will be stored on the stack - same as ints or any other type of value.

sepp2k 378 Practically a Master Poster

Floats in C are usually stored as 32-bit (i.e. single precision) IEEE floating point numbers.

sepp2k 378 Practically a Master Poster

C is not garbage collected. So the garbage collected is never called because there is no garbage collector (unless you're using a lib which provides one - in which case it depends on the lib of course).

The reason that your code (which of course invokes undefined behavior, so might technically behave any way it wants) behaves the way it does is that i contains an address on the stack. The first time you dereference i that address has not yet been re-used because you haven't invoked any other function yet. So it still stores the previous value of k, i.e. 12. The second time you dereference i, printf has been called and presumably stored something on that location on the stack. So it now holds whichever value has been stored there by printf. And that's the value that gets printed.

sepp2k 378 Practically a Master Poster

You set j to 0 once before the outer loop starts. So when the inner loop is run for the first time, j goes from 0 to 15. On the second iteration of the outer loop, j will still be 15 because you never reset it to 0 after the first iteration. If you add j=0 to the inner loop, j will be reset to 0 at each iteration of the outer loop.

PS: The fact that you used macros here instead of typing the loop out, makes no difference.

I_m_rude commented: yoo! great! +0
sepp2k 378 Practically a Master Poster

You have unclosed opening parentheses on lines 1 and 3.

sepp2k 378 Practically a Master Poster

The expression condition ? then_expression : else_expression evaluates to the result of then_expression if condition evaluates to true and to else_expression otherwise.

So the above expression evaluates to 1 if f is 0 and to f * fact(f-1) otherwise.

sepp2k 378 Practically a Master Poster

As for Linux, you can look for up-stream repositories that carry bleeding-edge GCC versions, or you can build it from source (as I do).

FWIW Arch Linux has gcc 4.7.1 in its main repository.

sepp2k 378 Practically a Master Poster

As I said, it's a new feature in C++11. It looks like either your compiler does not yet support C++11 or you didn't enable that support. If you're using g++, you need to add -std=c++11 to the command line (or enable the appropriate settings in your IDE).

Once you've fixed that, you'll still get error messages, but they won't be about your usage of using. Specifically you're using matrix where you meant to use array a couple of times. Also you can't use vectors as operands to cout <<.

sepp2k 378 Practically a Master Poster

Read the length of each word. For every word there will be space compare the string with the space if space found store the word in an array.

How is that better than using the split method to get an array of words like the OP did?

sepp2k 378 Practically a Master Poster

using my_type = old_type is a new syntax in C++11 which is basically the same as using typedef old_type my_type, with the important difference that it can be templated (whereas typedefs can't be).

So in the code you've shown, matrix<T> is defined as an alias for vector< vector<T> > (for all types T).