Salem 5,265 Posting Sage

So post your best attempt. Who knows, you may be closer than you think.

Salem 5,265 Posting Sage

> what about solving little/big endian problem by doing appropriate typecast before writing to file?
Because endian can't be fixed with a simple cast.
You have to write code to rearrange the bytes into the correct order.

> Is there any standard function to test the endianess of the system?
Not only is this non-portable (it assumes far too much about internal representations), it also assumes that there are only two endian systems (there's at least 3).
http://en.wikipedia.org/wiki/Endianness

vijayan121 commented: yes! +7
Salem 5,265 Posting Sage

There's no need to use the "I'm busy" card because those of us who've already done some kind of Computer Science degree already know there is way too much work and too little time. That's life, get used to it. Effective time management and doing just what is necessary and sufficient is all part of the deal.

I agree that you should definitely clarify the scope of the work while you've still got time to do something about it.

majestic0110 commented: Totally agree. +3
Salem 5,265 Posting Sage

> Terminates with: 'No source available for "fclose@@GLIBC_2.1() " '
You get these in debug builds because the code for fclose uses assert() to validate the input parameters.

If you were in a debugger at the time, you'd know exactly where to start looking.

In this case, fclose() is likely to begin with assert( fp != NULL ); Release builds have no assert() statements, so it would just return whatever the spec says fclose() should return if passed NULL.

Salem 5,265 Posting Sage
class dog {
  enum smells { poo, flower };
  smells nose ( object );
};

Instantiate the dog, then use the nose method to evaluate what a particular object smells like.

Nick Evan commented: Haha +5
Salem 5,265 Posting Sage

> It's in the bible
Ah yes, just like The Hitch Hikers Guide To The Galaxy, it "contains much that is apocryphal, or at least wildly inaccurate".

Oh well, one down, thousands to go. Is your basis of truth down to the number of people that that particular meme virus has managed to infect?

Salem 5,265 Posting Sage

That's because what I posted were NOT CHANGES, they were hints.

As in, you read them and then think about what they're saying, then apply that fresh insight to your specific problem.

Aia commented: A less popular but more admirable concept +7
Salem 5,265 Posting Sage

Hell, with only 2 posts, you've already joined the top 25% of posters on the board.
Only 8 more posts will get you into the top 2%!

John A commented: So true, so true. +15
~s.o.s~ commented: Heh. ;-) +21
Salem 5,265 Posting Sage

main always returns a value whether you like it or not, no matter whether you declare void main, or whether your compiler doesn't complain about it.

http://c-faq.com/ansi/maindecl.html

> so I wanted to know the reason behind this.
You're comparing a float to a double.
In the context of the if statement, f is promoted to a double, AND IN DOING SO changes value just enough to cause a shed-load of confusion. The 0.7 in your if statement is actually a double constant.
Writing if ( f < 0.7f ) might help in this instance, but doesn't change the underlying problems with the code.

0.5 (being a power of 2) can be stored accurately in a floating point number, so converting from float to double doesn't lose anything. But 0.7 is an approximation which gets even more imprecise with the conversion. You have to understand that < doesn't understand anything like "close enough".

http://en.wikipedia.org/wiki/Floating_point
http://docs.sun.com/source/806-3568/ncg_goldberg.html

Salem 5,265 Posting Sage

Excellent, let us know how that works out for you.

Aia commented: Clear and concise. +7
Salem 5,265 Posting Sage

This forum is nothing if not a compendium of all the different reasons why college students can no longer think for themselves.

Or even for that matter, ones which can be bothered to say read past threads or read the forums rules.

Has nothing you've learnt in the last couple of years sparked even the tiniest bit of curiosity to explore further. Or are you just another drone going through the motions in the hope that some magic bit of paper will give you the fortune and glory you hope for on a plate?

http://www.catb.org/~esr/faqs/smart-questions.html

hammerhead commented: Good link :) +2
Salem 5,265 Posting Sage

> vertex *ver1=new vertex(5);
> vertex *ver2=new vertex(5);
The results of any two memory allocations are un-comparable. Sure, right at the start you may convince yourself there's a pattern, but run any decent sized program for a while and try it again and the results would be all over the place.

> Similarly, why is the memory location of ver2 on heap 16+ memory location of
Depends how your allocator works. Very few allocators actually allocate just the amount you ask for. Most pad and align the requests in some way to balance performance against memory use. For example, all really small requests could be rounded up to say 16 bytes.

Plus there is the allocator overhead of storing information about each allocated block (like it's size), along with pointers to other memory blocks. Debug versions of the allocator can store additional information to assist with memory related problems such as memory leaks.

agrawalashishku commented: Thank you. That was very helpful!! +2
Salem 5,265 Posting Sage

This tells you to use code tags - http://www.daniweb.com/forums/forum2.html
So does this - http://www.daniweb.com/forums/forum8.html
Wait for it, wait for it - http://www.daniweb.com/forums/announcement8-3.html
You're not going to believe this - http://www.daniweb.com/forums/thread78223.html
And not forgetting the watermark at the back of the edit window.

Salem 5,265 Posting Sage
jephthah commented: that really is a good link. thanks +1
Salem 5,265 Posting Sage

Well that would depend entirely on your OS.

gcc in itself has no idea about graphics of any sort, it's all down to one or more libraries which interface to your specific OS.

A simple example might be to use ncurses, which is a nice simple console based API for generating user interfaces.

As for your 'OO' question,

typedef struct rec{
	char FName[10], LName[10], address[50];
	unsigned int TNum;
}REC;
typedef struct node{
	struct node* left,* right;
    char fname[10] ,lname[10];
    unsigned int tnum;
	char add[50];
}bintree;

There is no point to redeclaring all the members of rec inside bintree. For example

typedef struct rec{
	char FName[10], LName[10], address[50];
	unsigned int TNum;
}REC;
typedef struct node{
	struct node* left,* right;
	REC rec;
}bintree;

For one thing, it means you can then assign all the members of rec in one simple assignment rather than one at a time.

2. Replace all those char arrays with std::string - this is C++.

> REC r;
> bt trec;
There is no point in maintaining r as a member of each tree. It should be a local variable in the function which reads the file.

http://en.wikipedia.org/wiki/Model-view-controller
Think about separating your data from the presentation of that data.
Adding all that screen handling to your TD class is just going to make the whole thing messy.

rje7 commented: good.. thanks buddy +1
Salem 5,265 Posting Sage

feof() doesn't do what you think it should do.
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046476070&id=1043284351
feof() can only return true AFTER some other operation (say fread) has already failed. But you ignore that fread result, and thus what is left on the failed read is actually the same as the last successful read (hence the last line / record is repeated).

Use something like while ( fread( &section, sizeof (ADMISSION_DATA), 1, logger ) == 1 ) Generally speaking, you should be checking for success on all your other file operations as well.

knight fyre commented: help boost my understanding +1
Salem 5,265 Posting Sage

Maths lessons for new posters.

Before you post some massive post, consider the following.

1. There is a small number of regular helpers who end up answering the vast majority of posts (say 5),
2. Each such helper has a finite amount of time to spend on the forum (say 1 hour per day),
3. The number of posts in any 24 hour period across the C and C++ forums is say 60.

So assuming a perfect distribution of helpers to posters (which is of course false), the ideal scenario is that each helper can affort to spend an average of 5 minutes on a post.

And that's 5 minutes to
- read it,
- understand it,
- research answers, test possible solutions,
- compose an answer.

In practice, that means your initial post needs to be read and understood within a couple of minutes to be reasonably sure of attracting the attention you want.

In the first instance, you need to post one specific question, and a small section of nicely formatted code. You can then post more code if asked to do so later in the thread.

You're in competition with all the other posters for attention; Posts which
- are poorly formatted,
- overly long,
- don't get to the point
are going to sink to the bottom of the helpers' "to do" list, and probably fall off the end …

Salem 5,265 Posting Sage

# void main()
main returns an int.

# node* head_ptr;
An uninitialised pointer.

ayk-retail commented: Helpful! Thanks! +3
Salem 5,265 Posting Sage

In the same way that knowing some assembler gives you a deeper appreciation of C or C++.

It's all good.

Or perhaps you reach a point where the performance offered by a standard implementation just doesn't match up to the convenience, and you have to try and roll your own tailored to the specific set of circumstances you're faced with.

I think the point I'm trying to make is that knowing how to do something is not a valueless thing in itself, even if you never get around to doing that yourself. The ideas you'll learn will no doubt prove useful in the long run.

Ravenous Wolf commented: for what little my rep altering power is worth. thanks. +1
Salem 5,265 Posting Sage

> I really need your help in this one.
Why?
Notice how this is actually a question, which is more than you managed to post, which was just a dump of your assignment, and excuses for not doing it.

> Our professor asked us to program a simulation of soccer robots.
Perhaps this is the big test to see who gets to go forward to the advanced course, and who falls by the wayside. Harsh maybe, but that's life all over really.

If your combined desire + natural talent isn't going to get it done, then finding others on the web to do your work is only postponing the inevitable. That programming isn't your thing and you need to find some other path in life.

> I dont have mastery of programming
Now, does your professor know this as well, or have you been handing in other peoples work without fully understanding them (and the prof thinks you're better than you really are). Because most courses build up on information already learnt, and if you didn't learn it, it manifests itself as you coming over all clueless when confronted with the next assignment.
http://news.bbc.co.uk/1/hi/education/7194772.stm

Of course the other alternative is that your prof hasn't actually taught you how to program, and merely just spoon-fed the syntax of C++ to you.

Having said all that, a free bone

class player {
  // some things common to all players, like …
Salem 5,265 Posting Sage

CGI describes an interface which you can implement in a variety of languages (some easier, and more importantly, more safely than others).

Unless you own the box you're running the HTTP server on, your average sysadmin would baulk at running a program executable as a CGI on their machine. They much prefer tried and tested scripting languages.

Salem 5,265 Posting Sage

A few questions for your college / tutor.

Why are you teaching using tools, languages and operating systems which are at least 15 years out of date?

How do you consider this to be an effective preparation for the world after leaving college?

Have you ever had feedback from recent ex-students as to how they found the course, and how well it prepared them for their career?

When was the last time the curriculum was revised to meet the modern demands of students and prospective employers. When is the next such review due?

With the prevalence of many excellent, up to date and most importantly, free tools available, what other reasons are there for sticking with the old tools?

Regardless of whatever waffle you get in response, one likely reason is that the tutors themselves don't know enough C++ to move away from their comfort zone of that particular compiler. Their lack of real C++ knowledge would be exposed were they to use another compiler. It's easy to come to this conclusion because of all the "well my tutor said..." rubbish which is reported by students when we correct them here on the message board.

> so that i can display it using outtextxy() ...is that possible?
Of course it is.
If you've already managed to display a fixed string, then replacing that with a char array filled with data read from a file should be a breeze.
What exact …

Aia commented: Worth reading. +5
twomers commented: I hope that if you have a kid who is doing a programming class and the teacher is an idiot you'll record the conversation you have with them for us all to see. +4
Salem 5,265 Posting Sage

> You should copy test to a folder in your PATH variable,
This is a really, no REALLY bad idea.

1. There is already a standard unix command line utility called 'test', so by just copying it to somewhere in your PATH you risk either deleting it, or masking it with your program because it's earlier in the PATH.

2. If you really want a collection of your own stuff, then create a $HOME/bin directory for your own programs, then adjust your PATH accordingly (ideally, append $HOME/bin to the end of the current PATH).

WolfPack commented: Thanks. +7
Salem 5,265 Posting Sage

> i m using standard c++
Great, that really clears things up for us :icon_rolleyes:

> i need a complete program on it.
I'm sure you do.
And I'm also sure I could post one which works on my machine, but does nothing on yours.
Why, because you've not answered my first reply yet.

Oh, and read the intro threads on why we don't just give out complete answers just because you asked.

Jishnu commented: Absolutely :) +2
Salem 5,265 Posting Sage

My other suggestions would be to also consider Python and PHP, PHP in particular if you're into a lot of web stuff. Also on the "web-centric" list would be Javascript.

If your ultimate aim is to work professionally, then you'll end up knowing a couple of languages in depth, several more will be familiar, and yet more you'll be able to "get by with, if you've got the manual". With this in mind, which language you learn first doesn't really matter so much. And over a career, you'll learn new ones as well.

I was for example taught Pascal, but I never used it professionally, and I've never considered it a waste. It was just a practical manifestation of all the "how to..." information.

The choice for you at the moment is trying to decide which vehicle to buy without having learnt to drive. Nor have you decided whether you want to be in F1 or a road haulier.

For sure there are a whole set of skills unique to each, but there are also significant similarities across a very broad spectrum.

Continuing with the car metaphor, you'll want to practice in a nice easy car which doesn't bite back. C++ is a Ferrari. Fast and sleek to be sure, but also capable of being turned into instant wreckage unless you're careful.
C is also a Ferrari, but with somewhat loose steering, and suspect brakes ;)

The languages I mentioned above are good …

darkagn commented: Some good, friendly advice there and I especially like your car analogy :) +1
Salem 5,265 Posting Sage

There's a whole bunch of information (on IR and motors) on the site I posted way back in post #2, all for the sake of you showing some effort to read it.

You're not going to learn this stuff overnight, and we're not going to post it here over several hundred messages for you to digest one bite at a time.

It's like you're incapable of helping yourself.

I mean, if you posted "I've read <link>, but "this sentence" is confusing me", that at least would show that you're showing some initiative. But all you're doing is posting the same old "help me, I'm lazy" posts.

TBH, this kind of low-level development requires a hell of a lot more enthusiasm to read up on and try things for yourself than what you're showing at the moment. You're going to need that to investigate what's happened when it all does wrong (as it will do). If the only debug you have is a flashing LED, then you've got to get creative!.

Unlike portable ANSI-C which will work pretty much anywhere, any code you produce will only work on YOUR hardware. Which pretty much means you're on your own, and all we can do is offer suggestions (rather than answers).

Do you even have a hardware kit to hand? If so, tell us which one.
And I don't mean something vague. Be specific, post URLs.

Here's another forum which has lots of info on …

Jishnu commented: Exactly :) +2
Salem 5,265 Posting Sage

As good a place as any I've found.
http://www.lvr.com/serport.htm

iamthwee commented: Excellent link +13
Salem 5,265 Posting Sage

> Then fork another process to change zip file permission.
Or just use the chmod() API call instead of running the chmod command.

jobs commented: jobs: thanks for the help. +1
Salem 5,265 Posting Sage

http://www.codeblocks.org/downloads.shtml
Download "Code::Blocks IDE, with MINGW compiler"

In other words, join the 21st century and leave your fossil compiler in the museum.

Salem 5,265 Posting Sage

> I would like to add two things, simple sockets and simple multi-threading
So be damned to the portability to lesser machines which lack say a network connection?
All because you can't be bothered to write your own simple reusable network class.
Besides, in order to be "simple", it would have to leave out a lot of features. Which of course would make it instantly useless to everyone else.

Next people will be wanting graphics, sound, blah blah blah. All of which are far from platform neutral.


One thing I would like to see fixed are the parts of fstream which depend on C-style char arrays to represent filenames for example.

> but I was not prepared for the interview question.
Perhaps that was the point.
Most companies want people who can adapt and think for themselves, usually with less than complete information. They don't want walking encyclopaedias incapable of thinking for themselves.

Salem 5,265 Posting Sage

Only in the hope that the message will get across and that the OP will eventually learn that we're not here to rescue his ass because he spent too much time partying. The intro threads failed to get the message across, so it's time for a high impact approach.

The way to remove a leech is to hold a match to it. Such parasites suck the life out of forums such as this, by adding nothing and taking everything. If they even bother to return, it will only be to show defiance or sobbing. Neither of which will matter a bean.

If some other noob comes across this, they might just think twice about posting such a crappy post themselves.

zandiago commented: You tell em how it is! +2
Salem 5,265 Posting Sage

You have to change the signature of the compare function, to expect pointers to two character pointers, not pointers to two character arrays.

Ancient Dragon commented: Your right -- thanks +20
Salem 5,265 Posting Sage

I think I got to 10 bugs, then stopped counting.

Salem 5,265 Posting Sage

There should be a mandatory option on the ballot which reads something like this:
"I assert my right to vote, but I cannot at this time support any of the candidates listed".

Too often, the choices on the ballot are like being asked "choose how you want to die". At the moment, the only choice is for people to stay away. If there were a real option of telling all the politico's "YOU ALL SUCK", then a lot more people might show up to vote.

A significant problem is how safe the seat is. The safer the seat, the less effort the politico's spend on trying to win the votes and the less attention everyone gets. Advances in demographic predictions basically mean the real battleground can be isolated to a few key constituencies. If the vote in your area appears to be a foregone conclusion, people are going to be less likely to vote.

What should be banned is carping about the result if you didn't bother to vote in the first place.

Perhaps a "carrot" approach would work. If you vote, you pay 1% less tax.

EnderX commented: "choose how you want to die". Old age, thank you very much. +3
Salem 5,265 Posting Sage

You're not going to believe this, but there's this new fangled invention called "Da Interweb" which has useful tools like "Search Engines".

Take a trip to here as well, then read the rest of the ASQ (for that is what it is).

Jishnu commented: smartly handled :) +2
Salem 5,265 Posting Sage

> As you have got 1700+ posts , You can rent a link in your signature
> and earn $10-$20 per month per link in your signature.
Wow, so the 20K+ posts I've got scattered between my 3 favourite forums is worth what then?

Salem 5,265 Posting Sage

Great, you've got your free cookie, but have you learnt anything in the process?

> I definitely never would have been able to do it on my own.
Sure you would, eventually.
But instead you're dazed by vijayan121 'brilliance' rather than building up your knowledge towards your own solution. Which whilst it might have been longer, used less C++ features, would have been YOUR solution and not someone else's.

iamthwee commented: well said +13
Salem 5,265 Posting Sage

> this is urgently needed
I'm sure it is, but that isn't my problem.
http://www.catb.org/~esr/faqs/smart-questions.html#urgent

Nor am I interested in people in too big a hurry to read the forum rules, and completely ignore the copious references to USE CODE TAGS all over the forum.

zandiago commented: Want to establish a reading school? +2
Salem 5,265 Posting Sage

This should help you with your parallel port programming.
http://www.lvr.com/parport.htm

Jicky commented: that was a very useful link +1
Salem 5,265 Posting Sage

You can't calculate to 2dp using floating point.

Printing to 2dp is achieved by using I/O manipulators.
http://www.cplusplus.com/reference/iostream/manipulators/

johnnyjohn20 commented: gave me some very useful information via website +1
Salem 5,265 Posting Sage

Gee, yet another massive post from someone too dim to figure out how to use code tags despite the numerous places where they get explained!.

Good luck with that, I'm sure people will be only too glad to wade through several hundred lines of unformatted code for a fossil compiler :icon_rolleyes:

Killer_Typo commented: for as harsh as that comes off it needs to be said more often! +6
Salem 5,265 Posting Sage

It is also a terrible use of assert().

Assert is for checking program logic errors, like this

double mySqrt ( double x ) {
  assert( x >= 0 );  // no negatives please
}

The default action of assert is to kill the program stone dead. Your user is not going to be a happy bunny if after a long sequence of input the program just dies because of some stupid typo.

Another reason for not using assert on user input is that assert does nothing in the release build. So all your careful testing in debug mode with valid input is for nothing if the user "turns evil" on the release build.

So all your user input should be guarded with if statements to check for validity, not asserts.

vijayan121 commented: thanks +5
Salem 5,265 Posting Sage

> sorry buddy just try this out...
> #include<stdio.h>
> #include<conio.h>
> void main()

Great, just what we want around here, another void main, conio.h riddled post without code tags.

Salem 5,265 Posting Sage

scanf() uses the bare minimum of characters necessary to perform the conversion, and leaves the first character which cannot be converted on the input stream.

So if you type in
42\n
and scan that with "%d", then 42 will be used and \n will be left.

Now you come along with fgets(), and boom, first character is \n, and it's "thank you and good night from fgets()".

Aia commented: "...and boom". I like your special effects +4
Salem 5,265 Posting Sage

Use fgets() for everything.

So for example.

int Menu()
{
	char buff[BUFSIZ];
	int choice = 0;		/* menu choice value */
	/* with the following loop we force the user to choose
	 * on of the 3 valid answers: 1, 2, or 3
	 */

	do { 
		fprintf(stdout, "Please choose one of the following:\n"
				"1. do1 \n"
				"2. do2 \n"
				"3. do3 \n");
		fgets( buff, sizeof buff, stdin );
		if ( sscanf( buff, "%d", &choice ) != 1 ) {
			printf( "I asked for a number!\n" );
		}
	} while ( choice != 1 && choice != 2 && choice != 3);	

	return choice;
}

This also fixes your "what if they type the wrong thing" problem as well.

n.aggel commented: thanks! +2
Salem 5,265 Posting Sage

You have to wonder with so many "bullets" being fired at them how they manage to still get to the forum and still make a complete mess of it.

If they get an infraction (and a PM), they should not be allowed to post until they've read the PM and clicked on some "I acknowledge this infraction and will do better next time" link.

Ancient Dragon commented: great suggestion +20
Salem 5,265 Posting Sage

Study the interface which fgets() provides.

Salem 5,265 Posting Sage

> int noofgamesplayed; noofgamesplayed++; Is using it without it being defined. cout << "You played " << noofgamesplayed << " games"; Is also using it without it being defined. int noofgamesplayed = 0; Now we're cooking!.

dblbac commented: the information was great. +1
Salem 5,265 Posting Sage
Nick Evan commented: Haha I'll bet you 10 bucks the OP won't laugh halve as hard +2
Salem 5,265 Posting Sage

I suppose you could do this, just to see who's awake ;) for(code = *"A";code <= 0["Z"]; code += 1) /runs.

Ancient Dragon commented: good one! +20