Salem 5,265 Posting Sage

Consider this
23 = Twenty three
123 = One hundred and twenty three
123,000 = One hundred and twenty three thousand

So you need to think about (eventually)
- splitting into groups of 1000
- splitting hundreds from tens and units

But start simple, try to code up converting 1 to 99.

jephthah commented: you're really just a cuddly carebear, aren't you ;-) +4
Salem 5,265 Posting Sage

> Keeping all the weeds out of my lawn and garden.
Easy, you just need a system built using Windows CE, Windows ME and Windows NT :icon_cheesygrin:

vmanes commented: Yes! that's the solution. +4
Salem 5,265 Posting Sage

> PLzzzzzzzzz HELpppppppppppppppp
Loot at http://www.catb.org/~esr/faqs/smart-questions.html#bespecific

> I am trying this since 4 days but nothing.........
Yes, and nothing regarding your actual effort was posted either.

William Hemsworth commented: :) +3
Salem 5,265 Posting Sage

You haven't been trying to delete books anywhere else have you?
Deleting the same book twice is a sure recipe for disaster.

I see your addBook() returns a pointer to a book (why?). What else are you doing with that book pointer?

If you need to remove a book, then you need another member function, say delBook(), which removes the book from the set, and then deletes it.

Undertech commented: You were right, although it wasn't immediately obvious! +1
Salem 5,265 Posting Sage

Why is it so hard to tell people about the best way of doing it, rather than some old hack which they'll have to unlearn sooner or later?

It's not like there's a massive difference in line count (or anything) between the two.

stringstream (the basics of it) takes no more explaining that explaining atoi would. Probably less, if you exclude all the caveats.

Aia commented: Logic might get us not very far in this one. +9
Salem 5,265 Posting Sage
Aia commented: When would they learn not to clog the internet pipes. ;) +9
Salem 5,265 Posting Sage

Remove all phrases like this
- When posting programming code, encase it in [code], [code=syntax],

Remove all announcements like this
- Please use BB Code and Inlinecode tags

Remove all stickies like this
- Read This Before Posting

Remove the watermark at the back of the edit window

Why?
Because THEY DON'T BLOODY WORK!!!!!

Never, in the field of online forums, has so much been ignored by so many and understood by so few.

Noobs who get this right on the first attempt are so rare that they get +ve rep just for being awake. That's how rarely any of this stuff works. Chances are, that minority would have figured something out just from reading a few other posts and thinking, "hey, nice code formatting, how does that work?".

http://www.daniweb.com/forums/thread140124.html
Just the latest in a long (and never ending) list of bone-heads who can't even get it right even when you explain it to them.

So just get rid of it all, and we can just go back to yelling at them when they screw up.

~s.o.s~ commented: Rage against the n00bs? ;-) +23
Salem 5,265 Posting Sage

Congratulations - you failed to comprehend code tags. So now you'll have to wait for a mod to fix the mess you posted, and then maybe someone will read it.

Sometimes, it's just like trying to teach rocks to fly.

William Hemsworth commented: Haha, I agree there :) +3
Salem 5,265 Posting Sage

Not to mention - 2 YEARS TOO LATE!

William Hemsworth commented: heh, I didn't notice that x] +3
Salem 5,265 Posting Sage

Did you bother to read the link?
Did you get as far as "How to Apply These Terms to Your New Programs"?

Salem 5,265 Posting Sage
Alex Edwards commented: Why can't I stop laughing? XD +3
Salem 5,265 Posting Sage

To pass an array, you just need the name (no [ ] needed in the call)

Also, for loops should generally be < n ( and not <= n )
Yours runs off the end of the array.

Also, why not just say int a[10]; rather than initialising it with 10 elements which you're just going to overwrite anyway.

Don't forget, void main is wrong. Main returns int.

Salem 5,265 Posting Sage
Colin Mac commented: good link +2
Salem 5,265 Posting Sage

Thanks!!!
I'll be sure to let the "others" know :icon_rolleyes:

VernonDozier commented: Awesome! :) +5
Salem 5,265 Posting Sage

I can only be bothered to post this link.
Is it urgent?

> Develop a program in C++
Is that an order?

n.aggel commented: hehe, the scene from monty python rules! +2
Salem 5,265 Posting Sage

Try to imagine that I can't see your code.
Try to also imagine the 1000's of ways you can screw up.
Try to imagine that that was just a probable guess, not a guaranteed answer.

If you want any change of a real answer, post some real code.
Ideally, a complete program which crashes.

William Hemsworth commented: Haha, nice post.. made me laugh +2
Salem 5,265 Posting Sage
FILE *fp = popen("myprog.exe", "r" );
while ( fgets( buff, sizeof buff, fp ) != NULL ) {
  // do stuff with lines
}
pclose( fp );

Use _popen() on windows.

Alex Edwards commented: You deserve more than just +1 for all the help you give, but here you go. +2
Nick Evan commented: I'll make it +9 then +8
Salem 5,265 Posting Sage
do{
    } while (choice != 'c' && choice != 'C');

This should be your code to start with, then you compile it to see what the result is. If it doesn't compile, then fix it.

Then your code becomes

do{
        cout << "A: To Play the number guessing game." << endl;
        cout << "B: To Play the letter game." << endl;
        cout << "C: To quit program." << endl;
        cin >> choice;
    } while (choice != 'c' && choice != 'C');

Compile it again, and fix any new errors.

Then perhaps

do{
        cout << "A: To Play the number guessing game." << endl;
        cout << "B: To Play the letter game." << endl;
        cout << "C: To quit program." << endl;
        cin >> choice;
    } while (choice != 'c' && choice != 'C');
    switch (choice) 
    {
        case 'A':
        case 'a':
        break;
    }

Notice how you can add just a few lines at a time, and it will compile.

When you've done this a few times, then test what you've written so far to make sure it actually works as expected. If it doesn't, then fix those before adding more code.

In particular, note that the { } are never left out of place, or unbalanced.


What you've done is code beyond your ability to deal with the compiler throwing the whole mess back at you, so instead you dump it on a message board for someone else to fix. This …

VernonDozier commented: Great advice. +5
Salem 5,265 Posting Sage

Now remove the fread() which is inside the loop (line 13)

Salem 5,265 Posting Sage

Here's a procedure

if ( firstPostFailed ) {
    tryAgain();
}
Alex Edwards commented: Harsh, but funny XD +1
Aia commented: Not harsh at all. Creative, instructive and elegant. These are the right adjetives for it. +8
Salem 5,265 Posting Sage

So knowing what it does, you can write a spec which means there isn't a problem, or you can write a different spec where there is a problem.

I suppose pedantically, the parameter should be unsigned, if you're messing around with bits.

ssharish2005 commented: Totally agreee with you! +2
Salem 5,265 Posting Sage

How many times are you prepared to run across the road blindfolded, just because you managed to get across the first time without being run over?

Being right is a matter of attitude to solving the problem, not what your current compiler will let you get away with. Of course your next compiler may be a lot less lenient, but by then the damage has been done and you have to unlearn a bunch of crap (I know, I've been there).

Dave Sinkula commented: Me too. +15
jephthah commented: i love analogies +4
ssharish2005 commented: Love advices, respect - ssharish +2
Salem 5,265 Posting Sage

> I see. I was wondering, do you know if the prompt command box will delete initial output if
> the information being printed is too long or will it keep the entire history? It keeps chopping
> off and I am not sure if it’s something that I am doing wrong or if this is common?
Choose properties of your console window, then set the buffer size to what you want.
The max is 9999 lines.

Or you could always do myprog > results.txt and get all the output, no matter how long it is (well up to your file size / disk limits).

Salem 5,265 Posting Sage

> One more thing .. On one of my PC which has high power components... Like 7900GTX ..
Buy Ferrari.
Take out engine.
Replace engine with a horse.

Your compiler is the horse!

In one fell swoop, you've reduced your uber machine to an 8086 (and not the pentium-iv it has) with 640K of RAM (not the GB it has), and a VGA display with limited resolution and colours (and nothing like the graphics card you have).

Not to mention
- short filenames
- no knowledge of NTFS
- probable Y2K issues (gosh, really, that was like 10 years ago man)

Also (if that's not enough to convince you), dumb stuff like
char *buff; gets(buff);
usually works on DOS (for a while at least), whereas with any decent OS/Compiler, you get your ass handed back to you on a plate because it's such crap code.

For compilers
http://www.thefreecountry.com/compilers/cpp.shtml
http://www.compilers.net/
http://www.codeblocks.org/home
The latest visual studio express from Microsoft (+ the platform SDK), or code::blocks seem good choices.

And for graphics
http://www.libsdl.org/
SDL is a wrapped up version (simpler) than OpenGL (which you could also use).

Ancient Dragon commented: Great stuff :) +32
Salem 5,265 Posting Sage

Close enough.

And it won't work. Dev-C++ creates win32 console programs, not DOS programs.

http://msdn.microsoft.com/en-us/library/ms682064(VS.85).aspx
You could try messing about with the code page the console uses, but TBH, I've no idea what you might change it to.

At this point, I would normally recommend you start looking at UNICODE, which has a much larger character set. Somewhere in there you should find the symbols you're looking for. Then you hope that the font you've been provided with has glyphs at the code points of interest.

iamthwee commented: Nothing to add really, apart from the confusion between dos and the command prompt. +15
Salem 5,265 Posting Sage

In the blurb to encourage guests to sign up, there's this line.

"In fact, there are 4,267 IT professionals currently interacting right now!"
Nope, not by a long shot.

I bet a lot of people think "Wow, must be a great place, I'm sure to get my question answered here in about 10 seconds for sure".

Later down the page, the truth is revealed.
"Currently Active Users: 4434 (57 members and 4377 guests)"

"Oh man, what a rip - only 57 actual people - wtf". Then they disappear never to be seen again.

"Guests" cannot be included, because they can't post. If they can't post, they can't interact.
Sure, some of them will sign up during the day, but the vast majority of them will either never post at all, or just post "Hi, I'm Fred Flintstone from Bedrock" in the introduce yourself forum.
Would you call the google web-crawler an IT professional - I wouldn't.

Of the 57 actual members in the list, how many are "professional" in the sense that they have an IT related job which pays them money? I see a lot of students employing a variety of reasons as to why they're too lazy to attempt their homework, but I sure wouldn't want to be working along side them.

The number of people currently logged on with >100 posts would be a far more realistic measure of the degree of expertese the site currently …

Nick Evan commented: Good point +6
~s.o.s~ commented: Doh, I have been ripped off... ;-) +23
Salem 5,265 Posting Sage
jephthah commented: that's a really good reference. bookmarking now... thanks! +4
Salem 5,265 Posting Sage

> 1. In VS 6.0 (on Intel H/W) (are unsigned better?)
So, you pick one specific processor / compiler combination out of the many 10's of processors (or maybe hundreds of variants, or thousands of compilers + flag variations) and decide that proves it?
Interesting it may be, but it's not in my "useful" things to know when it comes to getting the best out of the code.

The whole point of using a HLL is to stop you from having to worry about the minutia of how specific machines handle specific cases, and thus allow you to concentrate on the bigger issues.

Any (let me say it again for the hard of reading, ANY) attempt at performance optimisation before you've finished the program and done some meaningful profiling is a waste of time. Focus your effort on choosing good data structures and algorithms, which will save hours (or months) of computing time, and let the compiler worry about the microseconds.

Your fast loop won't mean squat if you were dumb enough to put it in a bubble sort for example. There isn't an optimiser out there which can spot a bubble sort and decide to replace it with quicksort. That's YOUR job, so do it.

If you're finding your "optimised" code hard to read, then for sure so will the compilers' optimiser, and it will just chicken out and do exactly what you asked for.

Take those ridiculous attempts at swapping variables …

vijayan121 commented: ! +7
Alex Edwards commented: Omg... your post (#41) on page 5 was just too damn funny... +1
Salem 5,265 Posting Sage

Consider this to be the flavour of the problem rather than an answer (I don't have code blocks on this machine).

In the project settings, there should be a tab to configure the linker. Here you can tell the linker the places where to find other libraries, and the names of those libraries. It may already have the "standard set" of libraries already listed.

What you need to add to that is the name of the winsock library, which IIRC is called ws2_32.lib

Dev-C++ for example calls it libws2_32.a, so feel free to search for likely looking names ending in .lib or .a.

If code blocks follows the standard library naming convention, then libws2_32.a will simply be called ws2_32 on the linker command line.

Salem 5,265 Posting Sage

> but as I am beginner in C/C++
Unfortunately, reading schildt books won't clarify the issue either.

Pick a language and stick to it. Despite their recent common ancestry, and superficial similarity, using both of them well requires a C++ hat AND a C hat. C/C++ is just brain-damage.

> new allocates memory in C++ and java, how its different from malloc?
new calls an appropriate constructor, and malloc just gives you a block of uninitialised memory.

So in your case, you would need int *A = malloc ( size * sizeof *A ); > scanf("%d",(p+i));
You don't need p, just do &A[i]

grvs commented: helpful +1
Salem 5,265 Posting Sage

But "Fred Flintstone" reads as "Fred Flintstone" to anyone smart enough to use a hex editor.

Sure, if you write enough other binary data along with it, most simple text editors will barf on the file, but no hex editor will.

You could try encrypting the file, but by necessity, the key to the file will be in your program. So all you're really doing is reducing the set of people who would be able to hack your file format. But you're not going to reach zero people any time soon.

So, who are you trying to hide the information from, and how much effort are you willing to spend achieving it.

cam9856 commented: very helpful +1
Salem 5,265 Posting Sage

http://news.bbc.co.uk/1/hi/england/7423948.stm
There wouldn't be any need for "concern" if it were real, and not just a bunch of hooey to seperate the gullible from their money.

Strange, they didn't see that one coming :D :D - now that's comedy!

Besides, if they could really predict the future, why don't they win the lottery on their first attempt? Rather than spend their lives in some small hut fleecing sheep for pennies with vague phrases which could mean anything, and which can easily be "revised" after the event to equate to "success".

sneekula commented: very nice summary +4
Salem 5,265 Posting Sage

It's about time you read the intro threads and figured out how to use code tags.

William Hemsworth commented: definitely, getting tired of people in a rush to complete schoolwork and who dont bother with tags. +2
Salem 5,265 Posting Sage

IIRC, there are separate dialogs for passing options to gcc and g++

The gcc options I use when I want to be pretty strict about things are gcc -W -Wall -ansi -pedantic -O2 The two -W options turn on a lot of warnings (though not all of the ones which I would consider useful) which are practical for most common code.
The ansi/pedantic make sure it's squeaky-clean ANSI code
The O2 turns on all the data flow analysis to root out all those unused vars, use before initialisations etc.

VernonDozier commented: helpful. +4
Salem 5,265 Posting Sage

Sorry, but I'm not going to tolerate you mashing of the English language, so I'm going to ignore you instead.

jephthah commented: word. +3
Salem 5,265 Posting Sage

> (an aside to Salem, or anyone else: where are all these Turbo-C people coming from?
http://cboard.cprogramming.com/showthread.php?t=79702
Start at reply #8

jephthah commented: ah.. how illuminating. {Max} declared what I suspected, but could not say. +3
Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

It's not a binary file if you're using fprintf/fscanf to access the file. All the "b" mode will do is turn off any end of line translations, but since you never write a newline, this isn't an issue.

Further, you don't check the return result of fscanf(). You should. If it fails, you'll print garbage (and different garbage from one compiler to the next).
As in

if ( fscanf(fin, "%f %d", &fnum, &inum) == 2 ) {
  printf("reading the following data: %f %d\n", fnum, inum);
} else {
}

A single white space in a scanf call matches any amount of whitespace on the input.

3. Between writing and reading of a stream opened for update, you need to do fflush(fptr);

Dave Sinkula commented: It's been too long since I've added to your considereable rep. +14
Salem 5,265 Posting Sage

If all the minor dimensions are static, then you can allocate dynamically, and be contiguous with the result in one easy step.

int (*ptr)[CONST_SIZE] = new int [howmany][CONST_SIZE];
//
delete [] ptr;

If not, then you can allocate like this. It allocates space for the pointers, then space for the array itself. This can be extended to as many dimensions as you need.

#include <iostream>
using namespace std;

int main ( ) {
    const int rows = 3, cols = 5;
    int **arr;

    // allocate
    arr = new int*[rows];
    arr[0] = new int[rows*cols];
    for ( int i = 1 ; i < rows ; i++ ) {
        arr[i] = arr[i-1] + cols;
    }

    // populate
    for ( int r = 0 ; r < rows ; r++ ) {
        for ( int c = 0 ; c < cols ; c++ ) {
            arr[r][c] = r + c;
        }
    }

    // demonstrate
    int *contig = &arr[0][0];
    for ( int r = 0 ; r < rows ; r++ ) {
        for ( int c = 0 ; c < cols ; c++ ) {
            cout << (void*)&arr[r][c] << " "
                 << arr[r][c] << " "
                 << *contig << "  ";
            contig++;
        }
        cout << endl;
    }

    // deallocate
    delete [] arr[0];
    delete [] arr;
}

The results

$ g++ foo.cpp
$ ./a.exe
0x6a0268 0 0  0x6a026c 1 1  0x6a0270 2 2  0x6a0274 3 3  0x6a0278 4 4
0x6a027c 1 1  0x6a0280 2 2  0x6a0284 3 3  0x6a0288 4 4  0x6a028c 5 5
0x6a0290 2 2  0x6a0294 3 3  0x6a0298 4 4  0x6a029c 5 5  0x6a02a0 6 6
VernonDozier commented: Thank you for the helpful posts. +3
Salem 5,265 Posting Sage

Well if you ask someone to type "please", and they type in "plz", do you tell them they're right or wrong?
http://www.catb.org/~esr/faqs/smart-questions.html#writewell

Which operating system and compiler are you using?

What sort of C programming skill do you already have?

Salem 5,265 Posting Sage

What's 18 days in milliseconds ;)

Nick Evan commented: haha ;) +6
Salem 5,265 Posting Sage

No, he desperately needs to get off his ass and buckle down to some work.

> It has to be done in couple of hours as he has an exam tomorrow
Oh goody, http://www.catb.org/~esr/faqs/smart-questions.html#urgent
I suppose by tomorrow there'll be one less wannabe programmer who thinks they can get by in life from sponging off other people.

Tell me, why did you join this forum in an attempt to bribe a "pass" rather than your sibling?

> there are some ready made ones avaible , but they are either too complicated for a frshman
Wow, really?
Too complicated for your Bro maybe, but TTT should be do-able by any freshman.

What happens next year when the problems get harder? Are you going to pony up more money? If you're imagining that your bro will end up with a well paid programming job at the end of this and you'll get your money back, forget it. Your bro will be kicked out when they completely fail their first task because the degree they have is worthless.

> I ll buy a rapidshare account or send 10$ via paypal for those help me in this small project
For a few dollars more (I'm on a Clint Eastwood role at the moment, not that you would even care), I can post the answer direct to the tutor to save you both the inconvenience....

Aia commented: Post like this...priceless; for everything else Mastercard!! +7
jephthah commented: the punk was feeling lucky -- almost +2
Salem 5,265 Posting Sage

Well are you?

So, irrespective of the type of rep you give, why is the word "lucky" in the popup? Surely receiving rep is far more deterministic than the pure blind chance it suggests.

Perhaps when rep was blind and could be given anonymously, there was an element of chance.

This post made my day ;)

Ancient Dragon commented: I'm feeling lucky today too :) +29
scru commented: huh? i'm just not smart enough to understand you, you see. +3
Dave Sinkula commented: http://web.archive.org/web/20060109073954/http://www.moviesoundscentral.com/sounds/dirty_harry/punk.wav +14
~s.o.s~ commented: void main'ers are LUCKY ;-) +21
Salem 5,265 Posting Sage

Well since none of us attended your course, and apparently, neither did you, what exactly are you hoping to learn in the next 48 hours?

Without knowing the syllabus ("algorithms" is just too vague), we could tell you some good stuff, but it would be still useless for your immediate predicament.
http://www.catb.org/~esr/faqs/smart-questions.html#urgent

Sudden acts of repentance don't wash - fail the course and take it again, paying more attention this time.
http://www.catb.org/~esr/faqs/smart-questions.html#urgent

Or memorise this site
http://www.nist.gov/dads/

hammerhead commented: Excellent link thanks +3
Salem 5,265 Posting Sage

Many different kinds of ways of appearing to win an argument without actually doing so.
http://en.wikipedia.org/wiki/List_of_fallacies

VernonDozier commented: Good list. +2
Salem 5,265 Posting Sage

Process explorer can tell you about different kinds of memory allocation.

For example, it's possible to have say 1GB allocated to the process, but only 100MB actually mapped in memory at that moment. PE can show you both of these figures.

I would suggest you instrument your malloc/free calls so you have a trace of allocation (and amount) and free calls. You should then be able to simulate in a few seconds what it takes days to do normally.

Also get to use perfmon, which can be used to record performance statistics (eg. mapped and allocated memory) over an extended period of time. Perhaps the memory use is level and jumps unexpectedly in response to certain events.

jephthah commented: sage advice. im going to bookmark it for my own future reference +2
Salem 5,265 Posting Sage

How about msg db 'Simple Bootloader',0

jbennet commented: ty +30
Salem 5,265 Posting Sage

Designer Elephant thinks "eat the world"
That pretty much sums up all that happens in the lounge.

I suppose you could always vote elephant as well.

Brought to you by the letter Ω and the number 42.

jasimp commented: great summation +7
Salem 5,265 Posting Sage

> C'mon people I don't want you to do my work for me, just give me some help with ifstream!
Lesson number 1 - Don't bump your own threads with such comments only a couple of hours after your first post. We're not paid to be your 24/7 support, and we all have other things to do as well. It may well have been early morning in your locale, but those willing/able to help may have just gone to sleep for the night.

I'm assuming that leaving the data in the file is part of the exercise.

Use a std::vector to record the results of tellg() before you read each line. If you then want to go back to that line, then you can just seekg() to that position and re-read the line again.

You'll only need to read the file sequentially when the user asks for a line number greater than the max line you've read so far.

ithelp commented: N/A +4
Salem 5,265 Posting Sage

Evolution is a fact and a theory
http://www.talkorigins.org/faqs/evolution-fact.html

Also, the "how life got started" is a completely different question to evolution, which describes what happened after it did start. Finding say DNA (or not) on Mars / Europa in the next decade or two will certainly help in that discussion. Look forward to lots of back-peddling and "oh we didn't mean that at all" from the ID crowd.

Creationism is just "magic" invented by simpletons who just can't understand how the world works so they resort to "god-did-it-and-i'll-kill-anyone-who-says-otherwise" rhetoric. Which of course explains absolutely nothing.

The only difference being that people long ago stopped paying any attention to the "god-who-keeps-stuff-on-the-ground' and just accepted the theory of gravity as the explanation for why things do stay on the ground.

> No one will every know which if either is correct
But it isn't (nor ever has been) a 50:50 split. Evolution is like 99% and improving all the time, and the other thing is just a bunch of circular arguments which go nowhere.

People get by just fine on far worse odds than that, but somehow some people demand that if it isn't "100%" then that's the same as zero. Gimme a break.

jasimp commented: So true +7
sneekula commented: some very good points +4