Salem 5,265 Posting Sage

And so it begins.....

If someone isn't smart enough to think of a project to do, offering them a project title doesn't do anybody any good.

First they can't think of a title, so you suggest one.
Then they can't figure out what that means, so they ask you to explain it (we've reached that step).
Then you explain it. As sure as eggs are eggs, they're going to come back and ask you how to implement it.
Then actually help them to implement it.
Then how to debug it.

See where all this is going?

Before you know what's happened, you've earned another degree. Except it won't have your name on it.

@sam
You've got some keywords, start googling and doing some reading.

peter_budo commented: Interesting poem +22
Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

Correct indentation, and proper use of { } in all the places you need them would help.

Salem 5,265 Posting Sage

Yes, it's OLD C, and it defaults to int.

tux4life commented: Shortest working answer of the week (previous)? +19
Salem 5,265 Posting Sage

Debug assertions usually show up when you fail to do proper error checking.

Eg.

FILE *fp = fopen( "missing_file.txt", "r" );
// no check for success
int ch = fgetc( fp );  // debug assert here
Salem 5,265 Posting Sage

I've no idea then.

Did you start with an empty Win32 console project?

Salem 5,265 Posting Sage

Read the intro threads on how to use code tags.

Salem 5,265 Posting Sage

It's a pretty sure thing that you're looking at the effect rather than the cause.

Something else is probably trashing memory. Here is just where you first notice there is a problem.

In a correct program, there is no apparent difference between debug and release (except speed). That you are observing a difference is a sure sign of bugs.

It depends on how large the program is as to what to do about it.

One thing to do is examine carefully all your other classes. Especially any where you call new/delete explicitly.

Salem 5,265 Posting Sage

Sounds like the crappy PCH strikes again.


Try turning PCH off.
It's only relevant if you're compiling vast projects which are pretty stable.

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

> #include<iostream> using namespace std; Although its not good
Except it appears to be a C program from the logs.

But then again, who knows, the whole mess was posted without code tags to begin with. Don't people READ intro threads? Of course not, that would get in the way of being nice to readers.

> warning C4013: 'rand' undefined; assuming extern returning int
You're missing stdlib.h

And some others from the look of things.

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

http://msdn.microsoft.com/en-us/library/7dzey6h6(VS.71).aspx
Visual Studio 6 for example defaults to ANSI
Visual Studio 2008 defaults to UNICODE

The Win32 API functions (like CreateFile) are already wrapped, but many standard functions in the CRT are not.

Also, you need to use the TEXT() or _T() macro for ALL your string constants.

Read the rest of the MSDN link.

Salem 5,265 Posting Sage
if ( ReadBeforePosting() == true && PostHasCodeTags() == true ) {
  // reward OP with answers
} else {
  MoreCluesOnHowToDoBetterNextTime();
}
Salem 5,265 Posting Sage

> if i set timeout for e.g 5 seconds - while loop will be runed again after 5 secconds?
It will run
- when there is data to be read, or
- there is a timeout

Salem 5,265 Posting Sage

> How should i make my program go asleep and wake up when OS tells that i have something to read?
You just described select()

You don't need to do anything to make your process go to sleep, or to get it to wake up later on.

while ( (status=select(....)) >= 0 ) {
  if ( status == 0 ) {
    // timeout
  } else {
    // one or more file descriptors are ready, do something
  }
}
Salem 5,265 Posting Sage

Where did you get 1000 from?
Or indeed the idea that select() might be expensive, from the link you posted.

In principle, the process should be asleep in a select call until the OS wakes it up with something to do.

It's gotta be better than a bunch of poll() calls, or heaven forbid a while(1) loop.

Salem 5,265 Posting Sage

> recv( sock,buff,255,0);
1. You ignore the return result.
2. Despite all your memsetting, you still have the potential for a buffer overflow. If the recv() happens to FILL your buffer, there is no \0 at the end of it to mark the end of the string.
3. TCP is a stream protocol, so the minimum guaranteed number of bytes in a successful recv() call is 1.

The server might send "PING\r\n", but you might only recv() "PIN" on the first call, then "G\r\n" on the second call. This message reassembly is YOUR job to do.

It's a good idea to separate the "get a message" from the "process a message".

> So is there a way to change 'while' into some kind of 'when'.
Yes, look up the select call.
You can use this to wait for all sorts of sockets to become ready.
You can even supply a timeout in case you get bored of waiting, and need to go and do something else for a while.

Salem 5,265 Posting Sage

No, you read the rules first, then make an effort.

Salem 5,265 Posting Sage

> will the value of counter automatically change as well?
a) no
b) did you try it?

Salem 5,265 Posting Sage

> nextArray();
You said it needed a parameter, but you didn't pass any!

Try
nextArray(life);

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

You only enter a string, not a number.

Typing in 123
will likely get you
49 50 51
as output.

If you were expecting 123 to be printed, you need more code.
At the moment, you just print the decimal value of ASCII character codes.

Salem 5,265 Posting Sage

Read the manual?

http://www.cplusplus.com/reference/iostream/ifstream/

readfile.open("highscore1.txt");
if ( readfile.is_open() ) {
  // exists, do something like you're doing now
} else {
  // doesn't exist
  ofstream outfile.open("highscore1.txt");
  // yada yada
}
Salem 5,265 Posting Sage

> what if the file i am writing and reading to does not exist?
Test the result of the first attempt to open the file (you're assuming success at the moment).

If it doesn't exist, just write a new highscore table.

Salem 5,265 Posting Sage

You're reading AND writing the same file at the same time.

Read from the old one, write to the new one.
When you're done, delete the old and rename the new.

Salem 5,265 Posting Sage

> But at the end of the run it comes up with an Debug Assertion failed.
> WHY???

In your case, you're deleting what you didn't new.

If you don't call new for a pointer, don't call delete.

Examples.

int *p = new int ; .... delete p;
int *q = new int[10]; ... delete [] q;

If you used [] in the new, then you MUST use [] in the delete as well.

Other causes of trouble
- running off the end of the allocated memory (say by using <= in a loop rather than < ) MAY cause an assertion, or a segfault
- trying to delete the same pointer twice MAY cause an assertion, or a segfault
- doing some pointer calculations, and then deleting a pointer which is no longer at the start of the memory allocated MAY cause an assertion, or a segfault

Note that just because you do something wrong, there is NO guarantee of a run-time diagnostic. The surprise can be deferred until much later on.

Salem 5,265 Posting Sage

Once you have the Magick++ sources available, follow these detailed installation instructions for UNIX and Windows.

Did you follow?
It mentions the .h file you seek.

Salem 5,265 Posting Sage

ImageMagick is a program AND an API
http://www.imagemagick.org/script/index.php

Command-line Tools
Processing
Options
Usage
Program Interfaces
MagickWand
MagickCore
PerlMagick
Magick++

Salem 5,265 Posting Sage

How about burning a few CD's worth of less listened to music (or unseen photos) that you might have?

If you're scratching for a few MB, then you've got bigger disk space issues.

Salem 5,265 Posting Sage

The bin version is if you just want to run the programs.

The src is if you want to actually edit the program, read what it does, figure out how it works, make changes, fix bugs immediately etc etc.

Salem 5,265 Posting Sage

Also consider the lack of usefulness of a string containing only one char (a \0)

Salem 5,265 Posting Sage

Many of the commercial coding standards I've come across insist on using braces in all contexts, even the optional braces in 1-liner statements.

If you're using a syntax-driven editor, they come for free anyway, so removing them is work.

It also prevents "Arrgg!" moments, when attempting to add debug to say

if ( i < 10 )
    i++;
    printf( "i is now %d\n", i );

Coupled with bad indentation, and something less obvious than a printf, and it could be a while before you figure it out.

Basically, if there is one way which always works, then use it always.
Then by habit, that aspect of the program will always be correct.

If you have a special case you treat differently, then bugs appear when it ceases to be a special case and you don't notice the transition.

Salem 5,265 Posting Sage

It's a nice idea.
But there are at least 6 places where code tags are mentioned, and still about 99% of noobs fail to use them on the first post. People get +ve rep just for proving they can read - it's that rare!

Some continue to fail to use code tags despite numerous reminders.

Getting any of them to do anything more than press "submit" is hard work.

Further, where threads are marked as "solved", this can sometimes happen when the OP gets the first working answer (as opposed to the best correct answer).

Nor does marking a thread "solved" mean that some dimwit will happen along a few years later with some untagged "void main" horror just to show the world how little they know.

yellowSnow commented: Yep .. good points .. just me being a tad naive +2
Salem 5,265 Posting Sage

If you want to store 3.14 (and no more), then you need a different data type than a float.

You're always going to end up with either 3.139999999 or 3.140000001, depending on which is the nearest representable form to the value 3.14

Salem 5,265 Posting Sage

There's no such thing as an "array of bits" in C.

Salem 5,265 Posting Sage

Allegro is a graphics library (so no).

Try the STL instead
http://www.cplusplus.com/reference/stl/vector/push_back/

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

> what about Windows XP/ Vista and Command prompt? Efficient?
Dunno - maybe?
You would have to try a long test, write a large number of MB and watch what happens with say process explorer to see if any large temp files get created, and only one of the processes running at once.

As for the technique, you got it.
Though you might want to avoid mixing C and C++ I/O

Salem 5,265 Posting Sage

> for (int i = 1; i < nScores; i++)
In old C++, this meant

int i;
for ( i = 1; i < nScores; i++) {
}

Which meant you could re-use i later on in the same scope without having to redeclare it.


In new C++ however, i is now restricted to the for loop itself.
That is, it looks more like this

{
    int i;
   for (int i = 1; i < nScores; i++) {
   }
} // now i is OUT of scope

Meaning you can no longer legally reference i as a variable.

Your smart C++ compiler recognises that this would break a lot of old code, and helpfully tells you about the problem.

Either
- fix your single for ( int i to move the declaration of int i; just before the loop begins.
- add int to all your other loops.

Salem 5,265 Posting Sage

> how does --stdout work (as far as implementation in C++)? How can I output my words? Something with cout?
Exactly.
You parse your command line, and if some argv is "--stdout" then you output to stdout.
Otherwise, one would presume it expects a filename on the command line, and it would output to that file instead.

> then speed: would this method slow my code significantly?
This is entirely down to your OS/Shell.
On real operating systems (those with an IX in the name), pipes are a central feature of the OS and therefore very efficient.

On some dumb systems, pipes get faked by using files - you don't want to go there!

Salem 5,265 Posting Sage

You don't increment the dest array pointer.
The destination isn't big enough.

Salem 5,265 Posting Sage

It's trivial to achieve with -I. As an addition to the compiler include search path (for details, see your manual).

But if your only reason is "just because I want to", then it's not really recommended.

tux4life commented: Oops! Far better than my suggestion. +17
Salem 5,265 Posting Sage
Piya27 commented: nice programming language ;) +1
Salem 5,265 Posting Sage

Divide a number by 3.
Add that result to itself 3 times.
Are you back to where you started?

Salem 5,265 Posting Sage

> char comment;
How big a comment?

> counter[264]=depth;
Do array bounds mean anything to you?

What is depth?

The basics for a histogram is
counter[pixel]++
for all pixels

Salem 5,265 Posting Sage

If you haven't done so already, make sure you've got a backup of all your work, and copies of any non-standard drivers you might need, whilst you're still able to boot to normal mode.

Next, do you have the original boot CD for your OS?
You'll need it to run the recovery console, in order to do this:
http://answers.google.com/answers/threadview?id=215902
Try fixing the Master Boot Record with FIXMBR, then see if CHKDSK will run.

Failing that, I would guess running the "Repair" option from the boot CD would be worth a shot.

Salem 5,265 Posting Sage

Step 1

MPUSED=`lsof | grep $MOUNT | awk '{print $2}' | sort -u`

This makes sure that each PID which might have open files is captured only once.

Step 2
Then do

for i in $MPUSED; do
  echo kill -s SIGKILL $i
done
Salem 5,265 Posting Sage

*shakes head*
Did you copy that from the forum, or from your editor?

Where the *** is the indentation?

Look at post #6, that code is indented.
Yours is an unreadable mess.

It'sliketryingtoreadEnglishwithallthespacestakenout.
Sureyoucanjustaboutmakeoutthewordsbutitwouldbeahellofaloteasierwithsomespaces.

Salem 5,265 Posting Sage

You've already sorted the data, so the lowest will be at one end or the other.
Adjust your loop start/end condition.