tux4life 2,072 Postaholic

That's already a lot better, you're making progress :)
To find the length of the array you can do something like this: const int count=sizeof(array)/sizeof(int); or, if your array is always of the same length: const int count=4; ( const is optional in both cases, but I would recommend it in the second one) for (i=0;i<[B]=[/B]count;i++) has to be: for (i=0;i<count;i++) (otherwise you're overriding the array's bounds)

Now you've already the code to print out the whole array you've already completed 30% of your homework :P

tux4life 2,072 Postaholic

BTW, Why is there actually need for the file being opened in binary mode? Why don't you just use the text mode ?

tux4life 2,072 Postaholic

>I dont know of any way of Avoiding Enter.
You could use getche() or getch() from conio.h , but remember that it makes your code unportable ...

Edit:: A Borland-style CONIO implementation for the MinGW compiler: http://conio.sourceforge.net/ (though if you only want getch() or getche() you could simply use the ones which are provided in the simple CONIO-implementation which is standard coming with the MinGW-compiler)

tux4life 2,072 Postaholic

Can You please give me sample code??

Why should I? If I give you sample code, I'm actually doing your homework, so the answer is (and will always be): NO!

tux4life 2,072 Postaholic

Are you sure that you're a software engineer (as described in your profile) ?

10
20
30
40

(Just display the array)

10+20
10+30
10+40
20+30
20+40
30+40

(Take the first element and display all the elements after it, take the second element and display all the elements after it, take the third element and ...)

tux4life 2,072 Postaholic

Try to change your while loop to this:

while (in_file.read(reinterpret_cast<char*>(&i),sizeof(short)))
{
	i_abs = abs(i);
	out_file.write(reinterpret_cast<char*>(&i_abs),sizeof(short));
}
tux4life 2,072 Postaholic

You could get the computer's hard disk ID (hardware key), you can find some source code on how to do this here, but as already said the user can always replace a 'dead' part in his computer, so dealing with a unique computer ID will be way more difficult than it looks like on the first sight :)

tux4life 2,072 Postaholic

i GUESS YOU WILL NEED TO cin>>action; inside the while loop.

If you want the loop to run for ever each time taking in C.
U can do this

while(true)
{
cin>>action;
switch(action)
{
case 'c':
//DO something.
}
}

Isn't it better to just use an if-statement here (instead of a switch statement)?

tux4life 2,072 Postaholic

Have you tried reset the BIOs to default and/or back up data and reinstall the OS?

Hope this helps!
Bill

If it's a BIOS related problem, reinstalling the OS won't help much, otherwise if it isn't BIOS-related then it might solve the problem (in a drastic way)

tux4life 2,072 Postaholic

<---How do you remove posts?--->

You can't do it yourself, ask a moderator :)

tux4life 2,072 Postaholic

A switch with one case, it's allowed but I would use an if-statement instead :)

>actually, now everytime i hit enter. it's like I'm pressing c
You could also use cin.get() with 'c' as a delimiter (Though I'm not sure whether this is the best method to do this): http://www.cplusplus.com/reference/iostream/istream/get/

tux4life 2,072 Postaholic

TrueCrypt is full-featured and comes with source code (but the code will be big I guess) :)

tux4life 2,072 Postaholic

Yeah, but what is the need to put get between the pointer out anf the other object?

If you let a pointer point to a specific object, the arrow operator is used to access the (public) data members of that object (you can't use a . to call them because out is a pointer) out.get ( )[B]->[/B]Meta ( ).dump ( ); , take a look at this link: http://www.cplusplus.com/reference/std/memory/auto_ptr/get/ (that's the get() you mean)

Do you understand it now?

tux4life 2,072 Postaholic

out is a pointer which points to an object of a class called VideoData :)

tux4life 2,072 Postaholic

You said that we can not use -> on integer value. What about void?

If you write out.get() it will return an integer value (not a void ), but you cannot use the arrow operator (->) on an integer, it's intended for classes and structures :)

>I'm newbie to c++
Then you should start with the simpler things first, you need to understand the basics of C++ before you proceed on learning to more advanced parts :)

tux4life 2,072 Postaholic

Well, in this code it's possible. I don't know what does it mean exactly? I'm newbie to c++

If it's possible then there's probably something between the braces of out.get( ) , can you please post the whole line?

tux4life 2,072 Postaholic

Try what's described here: http://www.gamedev.net/community/forums/topic.asp?topic_id=456420 ...
What version of Visual Studio are you using?

ShadowScripter commented: Thank you for finding the link, and for your overall help. :) +1
tux4life 2,072 Postaholic

What does it mean to you something like this: out.get ( )->class ( ).function ( );

That's not possible, you can't use the -> operator on an integer value :)

tux4life 2,072 Postaholic

Hm, I'm really new to this, and I assumed that everytime you build a solution, it creates an executable?

How do I make sure it compiles as an exe? :S

Just choose Windows Project (when you create a new project)

tux4life 2,072 Postaholic

It's a debug compilation, if that means anything. Otherwise, I doubt it has anything to do with the problem :S

You just have to make sure that you compile DirectX programs as a Windows Executable :)

tux4life 2,072 Postaholic

>Is there any special method in c++ called get and which doesn't require instantiation?
>When i tried to find this method, I couldn't find it.
Well I could find it: http://www.cplusplus.com/reference/iostream/istream/get/ :P

Did you actually search? You can't just look over it, it's on top: http://www.lmgtfy.com/?q=c%2B%2B+get()

tux4life 2,072 Postaholic
  1. Is it only when you start your program in debugging mode that you're encountering this problem?
  2. Is your program working correctly outside the debug-mode?
tux4life 2,072 Postaholic

Already did that, but nothing changed. It still won't compile. Any more suggestions?

Yes, are you compiling it as a Windows Executable?

tux4life 2,072 Postaholic

After a bit of Googling

Just go to project properties -> Configuration properties -> Linker.
Go to -> General and set the "Additional Library directories" to point to your lib file directory.

Then go to Linker -> Input and type in your lib file name DDRAW.LIB in the "Additional Dependencies" field.

Hope this helps :)

tux4life 2,072 Postaholic

Where did you get that lib..

Actually DDRAW.LIB is part of DirectX SDK :)

tux4life 2,072 Postaholic

Try to pass the following arguments to your compiler: /EHsc /link [I]YourLib[/I].lib :)

Edit:: Maybe this is also helpful ...

tux4life 2,072 Postaholic

It just that i do not find the source code for Clamwin. I am new to antivirus programming and want to understand more how it works and make a small program. I know want a source code is and have already written assembly codes.

>...and want to make a small program
LOL, a small AV? It's at least 1000 lines or more I think :P

>I know what a source code is and blabla ...
It isn't because you know what 'source code' means, that you can actually understand someone else's source code

>...and have already written assembly codes
I hope you're not trying to write your AV in assembler (probably not, otherwise you weren't posting in the C++ forum), that will be a pain in the ... :P

tux4life 2,072 Postaholic

Why do you try to pass an fstream object?
Just declare an fstream object in the private section of your class :)

tux4life 2,072 Postaholic

Did you read my remark on system("pause"); in my signature ?
BTW, is there any specific reason to write this:

Node * head = NULL;
Node * tail = NULL;

?

Remark(s):

  • If you want let new return a NULL-pointer when allocation has failed, then you should use new(nothrow) :)
  • You don't check whether the memory allocation has failed or not, this is a bad programming practice :)
    I can't seem to find the code which checks for the 'C' input :( ...
tux4life 2,072 Postaholic

You'll have to use cin.ignore() to clean the input buffer, read this thread :)

tux4life 2,072 Postaholic

I did tried both and found relevant sites like the one provided. The problem was that I didn't know how to add the openCV library to my projects. The VS version I was using didn't have the options described at the link.

For Visual Studio 2008: http://opencv.willowgarage.com/wiki/VC2008Express :)

tux4life 2,072 Postaholic

Can you give me that code ?

tux4life 2,072 Postaholic

>Apart from that . The using of new operators and not deleting them is causing a memory leak everytime you run your code.
Absolutely correct! But normally today's Operating Systems clean up the memory automatically when the program exits, however, allocating memory and not releasing it back is not a good programming practice, don't rely on the OS to do the memory cleanup for you !

tux4life 2,072 Postaholic

Yup, using getline is probably the easiest way to achieve this :)

tux4life 2,072 Postaholic

? If you've hit a key once, you haven't hit it twice :P

tux4life 2,072 Postaholic

NathanOliver, your code won't work !!

tux4life 2,072 Postaholic

I dont think that this will work out.

string s="foldername//file";

The above function would remove the file"; part.

True, but keep in mind that this way doesn't work directly with C++ strings :) (however with a few modifications you can make it also work for C++ strings :))

tux4life 2,072 Postaholic

You could also use the following code to strip all the C++ style comments:

char expr[80]; // user inputted expression (with/without comments)
/* Strip down the '//'-comments */
char *p = strstr(expr, "//");
if(p) *p='\0';

expr now contains the expression without all the C++ comments :)

The C-style comments are a bit harder to do, but it's do-able :P

tux4life 2,072 Postaholic

if you don't know what the program ask and you don't know the answer then don't post, it's waste of time for someone that has a problem...........

you didn't help me!!!!!!!!!!
Thanks any way!!!!!!!!

If you don't know what you want then don't waste your time on this forum :(

tux4life 2,072 Postaholic

if you don't know what the program ask and you don't know the answer then don't post, it's waste of time for someone that has a problem...........

you didn't help me!!!!!!!!!!

How can we help you if you don't give us a thorough description of your problem?

tux4life 2,072 Postaholic

I'm sticking with Link list tho @_@

It's your choice, but remember that the list container from STL is also a linked list (a doubly linked list)

tux4life 2,072 Postaholic

I'm new..
Is memory leak problem solved..

We don't know, if he'll use vectors, the memory leak and his whole problem will be solved immediately :)

tux4life 2,072 Postaholic

I think that using vector of customers would be more appropriate for this .

Yeah that's absolutely right, I was so much into 'thinking in pointers' that I just forgot about doing it in the easy way :)

Black Star Uses character based input and not string based because, Its like a real Shop Scenario.
WHERE CUSTOMERS CAN arrive at any point of time.

I finally fully understand what he's trying to do, in this case using vectors is definitely the way he should go !!

tux4life 2,072 Postaholic

what if I don't use a vector of auto_ptrs

Then you're making it yourself difficult, but why don't you just get the whole line of 'c's first? The only thing left then is count how many times the 'c' occurred and use dynamic memory allocation to allocate the appropriate amount of memory for it ...

tux4life 2,072 Postaholic

I think that the user doesnt know how many customers are present.
So whenever a customer enters his restaurant(or any other shop) He presses 'C' to create a new
Customer Profile.
Is that the case BlackStar?

In that case it might be useful for him to use a vector of auto_ptr s :)

Yup, so the amount of customer profile = to how many times he presses c.

So you can actually just ask the user how many customer profiles he wants and get it as an integer for example?

tux4life 2,072 Postaholic

@Tux , basically that's what I want c to do.

Why don't you just get the input as a whole string then?

  1. Get the input as a whole string
  2. Loop trough the string character by character and if the character is a 'c' or a 'C' then you increase a counter by one, after the loop has finished you know how much structures you need in your array :)

Or...why don't you just let the user enter the desired number?

tux4life 2,072 Postaholic

so I should use a switch statement? instead of a if statement?

and I'm not sure how to move onto the next c on the input stream.

switch and if/else-if statements are essentially the same (they both evaluate conditions), but the difference between them is that a switch is executed faster and it's better for your code readability (if you're testing for much different values)

By the way: break can also be used to stop a loop (like the while or for loop)

tux4life 2,072 Postaholic

So if I didn't misunderstand you, you want:

  1. let the user press the 'c'-key on his keyboard and count the number of times the 'c'-key was pressed
  2. create an array of structures with as it's upper bound the number of times the 'c'-key was pressed

Is that right?

tux4life 2,072 Postaholic

You also have to keep in mind that there's a difference between the lowercase 'c' and the uppercase 'C' :)

tux4life 2,072 Postaholic

>would that fix the memory leak?
No
>also, how can I stop the infinite loop
use the break statement :)

By the way: Customer *head = NULL; is a very dangerous instruction, you're assigning a value to an unknown memory address :)