nezachem 616 Practically a Posting Shark

Hi All,
what is method to get all availabled disk drives and their status. By status I mean whether they are hard disk or CD/DVD or USB?

Practically impossible.

Also how to get list of Drives in *nix?
Thanks a lot

*nixes could be very different. In most important cases parsing /proc/diskstats does what you want.

nezachem 616 Practically a Posting Shark

i want to make an Object Test to control many threads.

Test.cpp

class Test{
	public:
		Test();
		void exampleThread(void*);
};

Test::Test(){
	_beginthread(exampleThread, 0, 0);
}

void Test::exampleThread(void* ptr){
	...
}

i get the error


what must i write so that i can make an Object control many threads?

thanks.

The short answer is you can't pass a non-static member function to _beginthread . The reason is that a member function takes a this pointer as a hidden parameter. Therefore the signature doesn't match. And of course there's no instance of Test that _beginthread knows about and could call exampleTest with.

For a solution read this. It talks about CreateThread ; I am sure you could adopt it to _beginthread as well.

nezachem 616 Practically a Posting Shark

Nezachem - I don't mean to imply, by my terse answers, that I have all the answers to the problem. I was merely pointing out one potentential problem that caught my eye.

If I sounded harsh, I owe an apology too.
You see, your original message by no means offered any help to the OP. His problem stemmed from the totally different mistake.
Yes I agree that strncpy raises a red flag. Seeing such construct everybody urges to jump out and say "hey where is the terminator?!". It is very important to suppress this urge and reread a problem. Otherwise the reply would only contribute to the entropy of the universe and a global warming.

You might have a valid point, however; whenever I see output such as what the OP supplied, and see a call to strncpy without explicit termination of the destination string (which is the input for fwrite: Garbage In Garbage Out) I see a red flag.

Surprisingly, strncpy was designed as it is (that is without placing a terminator) for a reason. In most situations calling for strncpy that extra '\0' would just stand in a way.

destination[strlen(source)] = 0, after the call to strncpy

Hmm... do I smell a buffer overflow here?

nezachem 616 Practically a Posting Shark

Shouldn't it have stored the pertinent values into itself (inside the loop)?

It is global all right, but it isnot global enough. It is global only within the process.
The parent initialize it to all zeroes. Each child gets its own copy initialized to zeroes. Each child puts some values to some slots - and it does not affect the copy owned by a parent.

What does it matter if the child is alive or dead at that point?

Try an experiment:
1. Comment out line 34 (a kill one) and
2. Modify line 43 to

cout << getpid() << ": " << pid_array[i] << endl;

and see what each process thinks about a state of pid_array.

halluc1nati0n commented: Great insight into the answer +1
nezachem 616 Practically a Posting Shark

What is the output?

What stops you from building and running this?

or a stack overflow in your "recurse" function.

What makes you think so?

nezachem 616 Practically a Posting Shark

I am not 100% certain where do you see the problem. If you are concerned with the fact that the lines 42-44 print out zeroes, that is what is supposed to happen. Each process has its own copy of pid_chk. The parent never modifies it, and the children commit suicide before reaching this loop.

nezachem 616 Practically a Posting Shark
if (waitpid(slave_control_struct[slave_id].pid, &child_exit_status, 0)) {

Keep in mind that on success waitpid returns a pid, not zero. Change your code to

if (waitpid(slave_control_struct[slave_id].pid, &child_exit_status, 0) == -1) {

PS: perror is not safe in a signal handler.
PPS: To answer your original question,

Does someone have a more general explanation on what the problem might be, when the wait-funciton returns with an error-code set to EINVAL, but the options seem to be set correct?

errno is only meaningful if the system call actually failed. In your case it succeeded.

nezachem 616 Practically a Posting Shark

At run time, things happen one step at a time. Let's trace the execution of your program with n being 2

while n != 1:
    # Python checks that n is not 1, and enters a loop
    if n % 2 == 0:
        # Python checks that n is even and enters the if-clause
        ...
        n = n/2 # [B]n becomes 1[/B]
    if n % 2 != 0:
        # Remember, n is 1, an odd number, so python enters the if-clause
        ...
        n = n*3 + 1 # [B]n becomes 4[/B]
    # while loop goes into next iteration, n is 4
while n != 1:
    # n is 4, enter the loop
    if n % 2 == 0:
        # n is even, enter the if-clause
        ...
        n = n/2 # n becomes 2
    if n % 2 != 0: # n is even, if-clause is not entered.
# Next iteration of while loop. n is 2. Etc, etc, etc
nezachem 616 Practically a Posting Shark

Let's see what happens when n is 2. Your first if condition is true, you divide n by 2 and it becomes 1. Now your second if condition is also true! Welcome to the infinite loop.

nezachem 616 Practically a Posting Shark

See that garbage character every 10? Which coincides with the size limit with the call to strncpy? Which doesn't automatically null terminate?

I sure do. I also see that the output is produced with fwrite(str, 1, i, stdout) , which cares not of null termination. I am absolutely sure that the counter i is plain wrong.

nezachem 616 Practically a Posting Shark

Are you guys on autopilot again? Beg to explain how null termination is related to the OP problem.

The real problem is that read_string doesn't return anything when it should.

nezachem 616 Practically a Posting Shark

Sorry. I trust GetLastError more.

it has been in all of the locations I've tried

What about the locations LoadLibrary tried? Is the file "test.dll" a library?

nezachem 616 Practically a Posting Shark

strcat (at line 31) doesn't work well with binary contents.

nezachem 616 Practically a Posting Shark

Something like this will work. Check your assembler docs for the syntactical specifics. What is important, you got the idea right.

nezachem 616 Practically a Posting Shark

What does GetLastError() say?

nezachem 616 Practically a Posting Shark

For ordinary numbers, its probably the O(exp), where exp is the
exponent. For example, base^exp, to calculate that it would probably take exp times to multiply base to get the answer.

It is at worst O(log(exp)). For example:
^2: x*x
^4: x2 = x*x, x^4 = x2 * x2
^8: x2 = x*x, x4 = x2*x2, x^8 = x4 * x4
etc.

In the general case, the multiplication schedule is a bit hairy (and finding the best one is probably NP-hard).

PS: this is assuming that a multiplication itself has a constant complexity, which is definitely wrong.

nezachem 616 Practically a Posting Shark

1. Please use code tags.
2. What errors are you getting?

nezachem 616 Practically a Posting Shark

I looked at the file. It's a very nice file. Still I have no idea what should be replaced with what.
Can you please explain this, assuming that I am going to play a computer, that is, exhibit an intelligence slightly higher than one of a amoeba?

nezachem 616 Practically a Posting Shark

OK, now you are getting somewhere. There still are few problems with this code.

First of all, I ran your code and I observed that the last reasonable result is obtained at x being equal to 88, where the calculated value becomes 1.4672884e+38 (the math library reports 1.6516363e+38). This is suspiciously close to 3.40282347e+38, which is MAXFLOAT as defined in <math.h>. Since then, your code reports inf, and the math library reports nan. Close enough.

However, things really start to deteriorate from x reaching 55. Until then, the relative error stays in e-7 range. From 55 up it starts growing up quickly. Which brigs the question on the loop termination condition. You break the loop after a 100 iterations. A hundred is a good number. It is big and round, but I'd like to see some logics behind it.

Using WaltP's advice I rewrote my code. (Thank You)

I don't know about WaltP's advice, it is definitely not an advice I gave you. The Horner schema advised by me kept stable - with the same 100 iterations - all the way to 60. Please meditate over this.

nezachem 616 Practically a Posting Shark

I've searched up fgets() , and on most of the websites I read that this is an un-save function which can return faulty values.

Either you searched wrong websites, or you misread them. Most likely they were talking about gets() (without a leading f) which is unsafe to the extent of never ever use it. On the other hand, fgets() is perfectly safe and sound.

nezachem 616 Practically a Posting Shark

And I'm not looking for an answer I don't want someone to write my code for me, I'm looking for assistance. If this is not the proper forum for such requests I'm sorry.

Please exhale. Relax. Read my post (it is just above), if you haven't done it yet. Understand why this calculation schedule avoids overflows and a whole lot of other numerical problems. Realize that it is a standard way of calculating power series. Implement it. And enjoy.

nezachem 616 Practically a Posting Shark

This is a very naive way to calculate power series. I bet you overflow the integer factorial much earlier.
If you look closely, the series can be rewritten as
1 + x*(1 + (x/2)*(1 + (x/3)*(..... *(1 + (x/n))))...)))
Now calculate it "from inside".

nezachem 616 Practically a Posting Shark

mv can't mass-rename. It can rename a single file, or move a bunch of files into a directory - that's exactly what happened on your second attempt.
For a windows-style mass-rename you need to do something along the lines of (untested)

for f in $filelist; do
    mv $f `echo $f | sed -e 's/S01E0\([1-9]\).*/10\1/'`
done

Don't forget to initialize filelist accordingly. Make sure I didn't mistype anything (I don't have a linux machine right now)

nezachem 616 Practically a Posting Shark

There is something wrong with an answer to the problem 4. Hint: an answer to the problem 3 is correct.

jonsca commented: Yup. I glazed over it! +2
nezachem 616 Practically a Posting Shark

It's nothing to do with bool. At lines 174 and 176 you attempt to compare the value returned by get_accountName to some string. However, get_accountName is declared void ; it returns nothing. The compiler tells you just that.

nezachem 616 Practically a Posting Shark
echo case2 = $1

doesn't do any assignment, it just prints stuff.
You need

case2=$1

or just

python StuDeleteMultipleLines.py $1

PS: why not do everything in python?

nezachem 616 Practically a Posting Shark

($ - $$) gives you the offset in the current section, that is, in .data. The way your code is written, the .data section will occupy whole 512 bytes.

You need a simple

times (510 - $) db 0
nezachem 616 Practically a Posting Shark

A vector doesn't have a sort method. You need

std::sort(fruitlist.begin(), fruitlist.end(), sortByName)

Do not forget to #include <algorithm>

nezachem 616 Practically a Posting Shark

scanf returns int , a number of processed fields. The inner scanf would return 2. The argument of the outer scanf becomes "%d %d" + 2 , that is " %d" - that's why it needs just one input. It crashes because the outer scanf does not have an argument to scan the value into. The

scanf("%d %d"+scanf("%d %d", &i, &j), &k);

will not crash.

nezachem 616 Practically a Posting Shark

Dimitar: I am afraid you are moving in a wrong direction. In a numerical analysis a "recursive integration" usually refers to a Romberg algorithm. Check it with your teacher before it is too late.

if the absolute value of the currentAreaUnderCurve minus priorAreaUnderCurve) is above delta
     then call func passing w/2 and currentAreaUnderCurve as arguments

I would grade this solution F. This approach suffers from early termination thus producing incorrect results, and the recursion is, let's put it mildly, artificial.

nezachem 616 Practically a Posting Shark
typedef cStudent StudentArray[30];

StudentArray is a type, not a variable. Therefore,

StudentArray[I].Display();

and similar is illegal. That accounts for all the expected unqualified-id errors.

nezachem 616 Practically a Posting Shark

Can you explain what 4-((double)i) is supposed to do?

nezachem 616 Practically a Posting Shark

Use code tag please.

Now:

while ((entry = readdir(pdir)) != NULL)
{
entry = readdir(pdir);
cout << entry->d_ino << endl;
if((entry->d_type) == DT_REG) {

You shouldn't do the second readdir. The way your code is written, you throw away every even entry. If the number of entries is even, your program sort of works (at least it doesn't crash). If the number of entries is odd, a readdir in a while condition returns a valid entry, a subsequent readdir (at line 3) returns NULL, and you have your segfault.

nezachem 616 Practically a Posting Shark

Quick and dirty:

static struct List * list_array[MAX_LISTS];

int create_list()
{
    int i;
    for(i = 0; (i < MAX_LISTS) && (list_array[i] != 0); i++)
        ;
    if(i == MAX_LISTS)
        return -1;
    list_array[i] = init_list(); // This is your regular init_list()
    return i;
}

int delete_list(int id)
{
    if(id < 0 || id >= MAX_LIST)
        return -1;
    struct List * list = list_array[i];
    if(list == 0)
        return -1;
    really_delete_list(list); // Your regular memory deallocation etc
    list_array[id] = 0;
    return 0;
}

// etc
nezachem 616 Practically a Posting Shark

Look at line 5. grep found itself. It's pid among others is passed to kill, yet grep has already terminated.

nezachem 616 Practically a Posting Shark

The only thing which comes to mind is to use handles (aka descriptors). The handle-based code does not expose a struct list in any form. An init function returns an opaque handle instead. Of course it needs to maintain an internal registry of allocated handles and a handle-to-list map.
As an example of such approach look at the file descriptors and their open/read/write/close system calls.

nezachem 616 Practically a Posting Shark

Look at Midnight Commander. It's an open source, so feel free to study how they have done all those fancy widgets in a console. Or, better yet, make your program as a plugin.

nezachem 616 Practically a Posting Shark

I was just hoping there was a better way of identifying what a port is running

AFAIK, no.

nezachem 616 Practically a Posting Shark

Just to be sure, what does IsWow64Process say?

nezachem 616 Practically a Posting Shark

Well i think you arent getting the point. I am aware about the output and how it is coming but the gist is
"I want the ascii of that character to be printed i.e 100 for d . So ,if the file contains a list of characters , i need the program to display the ascii of these letters not the binary equivalents , besides the operation should be reversible i.e to get back the characters from their ascii notations. "

Well i think you arent getting the point.
Your program does print what you want. In decimal. It is just a bad luck that the codes for all characters in your file have only ones and zeroes, which gives an impression of binary. Try some other letters.
Since you do not print any delimiter, the codes are printed back to back, and there is no way to reverse it.

nezachem 616 Practically a Posting Shark

I got over the frst problem, but what should I need to do in order to handle with case like: printf ("%d\n", lowest_ever (-1));
???

return lowest_num anyway, perhaps?

You still have a small problem though. You shall not call va_arg until you sure there is a next argument. Besides, the call to lowest_ever (-1) sets lowest_num to -1; that is not likely what you want.
To deal with all this I'd restructure it as follows (you've done enough to see the solution):

int lowest_ever (int frst,...)
{
  va_list mylist;
  static int lowest_num=101;
  int  num;
  
  va_start (mylist, frst);		/*Initialize the argument list*/
  for(num = frst; num != -1; num = va_arg(mylist, int)) {
	  if (num <lowest_num)
		  lowest_num = num;
  }  
  va_end (mylist);			/*Clean up */
  return lowest_num;
}
nezachem 616 Practically a Posting Shark

Your code:

static int lowest_num;
  static int  next_num;

Do you listen this well in class too?

Strictly speaking, this is one of the rarest situations where static is called for:

that finds the smallest number in a several unknown function calls

nezachem 616 Practically a Posting Shark

I know this can be done by a command in *nix systems called nmap, i just need to do it in python, and it to be cross platform to lindows.

Question sustains.
Do you have a particular problem with python, or do you need help to understand portmapping in general?

nezachem 616 Practically a Posting Shark
int lowest_ever (int frst,...)
{
...
  while (next_num!=-1)

Man... turn on your logic. Or even better use a debugger. When you call lowest_ever(-1) , what do you think frst would be?

nezachem 616 Practically a Posting Shark

since mini = i

Indeed? mini may well change by an inner loop. Pay attention to line 6.

Now, regarding complexity. You outer loop executes k times. Right?
Each iteration consists of lines 3, 7, 8 and 9 - their execution time is constant (that is, it doesn't depend of neither n nor k ) - and an inner loop. Right?
The inner loop executes n - i times; each iteration time is at least a time of comparison, and at most a time of comparison plus a time of asignment, which from the complexity perspective is also a constant. Right?

Summing it up, the total time is

Sum{i}[1..k] (const1 + (n - i) * const2)

that is

const1*k + const2*n*k - Sum{i}[1..k](i) * const2

that is

const1*k + const2*n*k - const2*k*k/2

Right?

Again, from the complexity perspective, nobody cares about the linear term. Finally, the complexity estimates as O(n*k - k*k/2). If k is o(n), the second term may also be eliminated, giving O(n*k).

Right?

nezachem 616 Practically a Posting Shark

Show me your code.

nezachem 616 Practically a Posting Shark

I just realize you have it static. Of course it wouldn't work. You need

if(frst < lowest_num)
    lowest_num = frst;
nezachem 616 Practically a Posting Shark

to not ignore always the first number in the list

static int lowest_num=frst;

how to handle with call like: lowest_ever ( -1);

if(frst == -1)
    return -1;
nezachem 616 Practically a Posting Shark

Look at sprintf() then.

nezachem 616 Practically a Posting Shark

Do you know how to do it in any other language?