Sci@phy 97 Posting Whiz in Training

Line 8 of your code is:

string constructor (string str, int number)

Line 9 of your code is:
string constructor (char* arr, int number)

It's been awhile since I wrote in c++, but i think you can understand this.
The point is that if you type "Initial", that's not object, it's array of char's

Sci@phy 97 Posting Whiz in Training

Thank you once again. I'll look it up

Sci@phy 97 Posting Whiz in Training

Have you called srand()? You need to seed the numbers first. You can look at this example:
cpp useful webpage

EDIT: ok, I see srand now :D...
Try to break your code a bit... segment by segment, to pinpoint exactly where it goes wrong...
For example, try to print rand(), to see what it puts out... etc...

Sci@phy 97 Posting Whiz in Training

Thanx for your answers.

Actually, t.go = False has really good effect, t.isAlive() gives me False.
I can't use t.join(), because I want to use thread t to write information from serial port to a file, every x seconds or so. At the same time, I have to be able to stop writing to file from main thread.
I'm pretty new to whole concept of threads, so maybe there's more simple solution.

Sci@phy 97 Posting Whiz in Training

Thanks for the reply. The code above only writes "time exceeded" after the person has finished the quiz. Is it possible to prompt the command even if the user doesnt enter anything? Lets say he's only less than halfway through the quiz.

It is possible, and it is called "threading".

The problem is that code like this is executed one line at a time. So, there's no way your program can count down AND wait for your input at the same time, without threading.

It basically means you assign part of the program called thread to do the countdown, while at the same time your main program waits your input.

The entire coding and process isn't quite simple, and quite honestly, i don't know how to do it, but if you really want, you can look up some tutorials. Have fun

Sci@phy 97 Posting Whiz in Training

Hello. I've just started learning Python and I have a few questions.

I'm using my program to communicate with some device through serial port using serial.py library. It's all going really fine.
I've got a class device, and I'm using it to communicate with a device (logical ;) ).

Q: is it better to open port in class __init__ method and close it in __del__,
or is it better to open-close it every time you send and receive a string through port?

Another question is why can't I re-start thread that has finished executing? My code for that is:

class thread1(threading.Thread):
    def __init__ (self, br):
        threading.Thread.__init__(self)
        self.go = True
        self.running = False
        self.br = br

    def run(self):
        self.running = True
        for i in range(1000):
            global v
            if self.go:
                vlock.acquire()
                v += self.br
                vlock.release()
                time.sleep(1)
            else:
                break
        self.running = False
        return 0

So, I start thread

t = thread1(1)
t.start()

,
let it run for a while, and then set

t.go = False

, which terminates thread. After that I try again to start

t.start()

, and it gives me

RuntimeError: thread already started

Is there any way you can do that, or I'm simply trying impossible?

Sci@phy 97 Posting Whiz in Training

If you are running it under Windows XP CMD than it will only affect that window, because XP just simulates command prompt, doesn't load real one.
So, answer to your question, if you are running XP, is NO

Sci@phy 97 Posting Whiz in Training

>>AFAIK brackets can be used without any function or if statement, simply as code-block.
They just come in handy for functions, classes, etc.

That would be interesting.

I'm stunned. Can somebody tell me if bracket section alone is by C/C++ standard?
Because, DevC++ mingw and Visual C++ Express 2008 both compile and execute properly:

#include <iostream>

int main(){
    int a=5;
    std::cout<<"Out of bracket:"<<a;
    {
        int a = 6;
        std::cout<<"\nIn bracket: "<<a;
    }
    std::cout<<"\nOut again: "<<a<<std::endl;
    
    std::cin.get();
    return 0;
}

Providing output:

Out of bracket: 5
In bracket: 6
Out again: 5

Sci@phy 97 Posting Whiz in Training

AFAIK brackets can be used without any function or if statement, simply as code-block.
They just come in handy for functions, classes, etc.

Sci@phy 97 Posting Whiz in Training

Please post entire code, because your code should work then.

Sci@phy 97 Posting Whiz in Training

You have to do it for EACH i.
So put it in for loop

Sci@phy 97 Posting Whiz in Training

Oh, yes... Your temp is actually same memory space as ptr. So:

temp[0] = ptr[99]
...
temp[99]=ptr[0]

But ptr[0] is temp[0], which is actually ptr[99]

You have to make a REAL copy of ptr to temp, where: temp != ptr , but temp[i] == ptr[i]

Sci@phy 97 Posting Whiz in Training

I apologise, my bad (still early in the morning here :) )
I just realised that you decrease ptr_size2, not ptr_size, so it shouldn't be problem there.

Sci@phy 97 Posting Whiz in Training

I only gave you an idea... Probably I messed up some interators, so in some point you call temp[negative]...
Check for this, it shouldn't be hard

Sci@phy 97 Posting Whiz in Training

Problem is you are going both ways!
You are incrementing i iterator and at same time decrementing ptr_size2.
Write something like:

ptr_size2 = ptr_size;
temp = ptr;
while (ptr_size2>=0) {
temp[ptr_size-ptr_size2]=ptr[ptr_size2--];
}
Sci@phy 97 Posting Whiz in Training

What do you really want? How to create Clist? or?

Sci@phy 97 Posting Whiz in Training

What have you done so far? We don't solve homeworks

Sci@phy 97 Posting Whiz in Training

What does Earray point to? You've made it to null pointer: Earray[i] = 0 //like NULL And your EmpPointer is unused...
Seems like to me you're trying to allocate 2D array of some sort, but doing it wrong

Sci@phy 97 Posting Whiz in Training

It works on my Dev-cpp (mingw, gcc) compiler, and I can't see any problem with code, so it's probably something about your compiler.

Sci@phy 97 Posting Whiz in Training

why do you need kbhit? kbhit works more like a detector if key is pressed, it doesn't wait for keypress.
Simply use getch?

Sci@phy 97 Posting Whiz in Training

Please post at least head of your header file...

Until then, this: googleing!

says this:

Linker Tools Error LNK2001

unresolved external symbol "symbol"

Code references something (such as a function, variable, or label) that the linker can't find in the libraries and object files.

Possible causes

* What the code asks for doesn't exist (the symbol is spelled incorrectly or uses the wrong case, for example).
* The code asks for the wrong thing (you are using mixed versions of the libraries, some from one version of the product, others from another version).

This error message is followed by fatal error LNK1120.

Sci@phy 97 Posting Whiz in Training

Well, you obvioulsy need to increment counter each time you add a node, and decrement it each time you remove a node. It's really not hard, just put it in insert, delete, and create list.

For checking if list is empty... simply check if first==NULL.

But don't you need some wrapper class around everything? This way it's meaningless to write empty() function

Sci@phy 97 Posting Whiz in Training

hmm... write your own mul using logical operators and and or?
I'm a beginner too, so don't really know how, but I'd try something with that

Although it's not elegant solution

Sci@phy 97 Posting Whiz in Training

Hi! I have the following code:

mov al, 5d
neg al

When it executes, CF = SF = AF = 1
Ok, I think I understand why
AF (number is bigger than 00001111b ?),
SF (most significant bit is now 1 not 0)

But what I don't understand is why CF?
I thought it happens only if you go out of boundaries, like if result exceedes FF (100h or above can't fit in bit)

Please, help poor begginer :)

Sci@phy 97 Posting Whiz in Training

Make pointer to pointer **ptr , and allocate n pointers to it.
Then to each of that n pointers *ptr[i] allocate n int's (or whatever).
After that you can use it as regular 2D array: ptr[i][j]

Sci@phy 97 Posting Whiz in Training

Hello to all of you!
I would really appreciate somebody telling me complete step by step tutorial how to work with MASM (or TASM, but I haven't noticed it's free to download)

I've tried myself MASM and TASM (some Telemark assembly, not Borland), but for some reason it won't work, it reports some errors found, and I don't believe code is problem :(

.model small
.stack
.data
message   db "Hello world, I'm learning Assembly !!!", "$"

.code

main   proc
   mov   ax,seg message
   mov   ds,ax

   mov   ah,09
   lea   dx,message
   int   21h

   mov   ax,4c00h
   int   21h
main   endp
end main

Oh yes, I have Intel Centrino Duo processor, Windows XP HE, if it means something.
As I said, I'm newbie to assembly, so I would really appreciate help.
Thank you

Sci@phy 97 Posting Whiz in Training

thanx for replay
can u explain briefly

I used void so, there is no need to return any value

You can drive your car without fastening seat belt, or walk through minefield :)
But it's risky!

So always use int main() and return zero if succesful (in which case you don't even need to write return because compiler does it automatically for you.

Sci@phy 97 Posting Whiz in Training

What you wrote will only chage 101'th element of array1 with 101'th element of array2.

To copy arrays, you have to write function that will do that for each element

Sci@phy 97 Posting Whiz in Training

Let's say you have arrays: int arr1[N], arr2[N]; Then arr1 and arr2 are actually pointers to first locations in arrays, so this would be true:

arr1== &arr1[0]
&&
arr2==&arr2[0]

Now you can see where I'm going at:

arr1 == arr2
//is like
&arr1[0] == &arr2[0]

So it evaluates adresses of these two arrays, and if they are same it is true.

If you want to really evaluate arrays, you will have to write function that evaluates each member of array

Sci@phy 97 Posting Whiz in Training

If I'm not mistaken, fillellipse draws standard (unrotated) ellipse, and there's nothing you can do to rotate it. You could try to draw your own ellipse, and then do something with that...

Sci@phy 97 Posting Whiz in Training

Using '%' and '/' should be sufficent. First take a modulo 10 of number (and that is your last digit), then divide number by 10 (and you are left with number without last digit). And put that somehow in a for loop

Sci@phy 97 Posting Whiz in Training

And a little piece of advice. When working with decimal numbers, don't use float, instead use more precise double.

Sci@phy 97 Posting Whiz in Training

Also, when working with classes that allocate memory dynamically, you HAVE to write destructor that will free all allocated memory!

Sci@phy 97 Posting Whiz in Training

Oh yes, sorry. I thought minus was problem :)

Check your spelling, and learn how to read errors.

Sci@phy 97 Posting Whiz in Training

- radius = r; Hmm...
What's wrong with this code: -a = 300;

Sci@phy 97 Posting Whiz in Training

Try to see if the problem is input or your class.
Remove all user inputs from main and put something yourself in it. If it works, problem is only in input.

Sci@phy 97 Posting Whiz in Training

Do you know why do you use typedef?
It's syntax should be:

typedef some huge type A_DEF;

And the code you wrote has no use from typedef since you haven't specified name that will replace that struct.

Sci@phy 97 Posting Whiz in Training

Funny:

typedef struct node { 
	char value;
	bool isroot;
	bool isend;
	struct node* sibling;
	struct node* child; 
}; //<== if semicolon goes here, it's much more reasonable
Sci@phy 97 Posting Whiz in Training

What doesn't seem to work?

Sci@phy 97 Posting Whiz in Training

The array declaration int a[n]; is not valid C++. Your compiler doesn't complain because it supports this as an extension. (Your compiler might also support the 1999 C standard (where such things are valid)).

So, that's the thing! I knew something was wrong with it, but still :)

Sci@phy 97 Posting Whiz in Training

Why don't you check if it's open?

current_file.open(file.c_str());
if (!current_file){
    cout<<"File not opened!\n"
    return "";
}
Sci@phy 97 Posting Whiz in Training

Glad you've find answer. But this is what you asked (be careful what you ask :) ):

Is there another way to create an array of objects size of which is unknown without using new key(without malloc too)?

Sci@phy 97 Posting Whiz in Training

Don't know if it helps. I myself am not sure if it's ok to write it, but compiler doesn't complain:

void func(int n){
    int a[n];
    for (int i = 1; i <= n; i++) a[i+1] = i*i;
    for (int i = 1; i <= n; i++) std::cout<<a[i+1]<<std::endl;
    return;
}
Sci@phy 97 Posting Whiz in Training

d is c++ string object, and printf is C function.
Even more, not only it's C function (it would probably work nevertheless), but you've told it to print integer ( "%d" tells printf to print integer!)

Sci@phy 97 Posting Whiz in Training

And what exactly is the problem?

You have no syntax errors, and I can't see anything wrong. But i'm sleepy, so maybe I'm wrong...
Please be more specific

Sci@phy 97 Posting Whiz in Training

Ah, now you've said your problem. Solution is simple:
AND && (notice, two & signs)
OR ||
NOT !

Sci@phy 97 Posting Whiz in Training

You should check your microphone. It can sometimes be a problem (conflicts with compiler for c++)

chococrack commented: R O F L @ microphone compiler issues +1
Sci@phy 97 Posting Whiz in Training

because your for loop is counting for you, and still, you are counting for yourself in
if (num%two==zero)
{
sum=sum+num; ctr++; }

Sci@phy 97 Posting Whiz in Training

Why not simplify things? num=rand()%(max+1);

Sci@phy 97 Posting Whiz in Training

You should use while loop, not for.

And you haven't declared 'two' and 'zero'.
Why don't you simply put 2 and 0?