WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

C'mon guys, the answer is simple.

why C is a not a object oriented program ?

Because it was designed as a procedural language. Simple as that.

Salem commented: One single moment of clarity, then C++ was invented ;) +36
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

gurdeep kaur, how does your post help Lenny19 with his problem? Or do you have a new question which needs to be asked in it's own thread?

Before starting your thread, read some of the posts that explain how to post your question properly, which includes The Rules.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hello all,

in time of need I always come here to cry for help)

Anyways. What I need to do is to store data about people in a binary tree. They need to come from a file, but for now I can hardcode them in.

Well, I suppose the first thing you could code is the input function and get that out of the way...

To put it simple, I will have 10 people (probably defined as structures with name, surname, age, phone number variables) where surname acts as a key.

I am totally new to binary trees - does it mean I will need to have a tree of structures? I have some sample code, but it only works for numbers, how can I modify it so it will take structures?

Yes. How to modify your code? Replace the integer data field with your structure data. The integer information is already defined in a structure, is it not? Just replace it with all the fields you need to keep track of.

How do I go about it? General tips and even code would be great!

Use your editor... Since you posted nothing, I can only guess -- or use my psychic powers. Which would you like me to do? :icon_wink:

Also, I found some sample code and it has weird "->" symbols - what do they mean in my context?

A structure element is referenced using a dot, as in person.age , get the age field …

Lioshenka commented: Thanks +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Since we know the program you posted cannot possibly compile, and you claim it's actually running, you need to repost the current code you're compiling. And then explain in detail what the program if doing wrong. Don't make us search for it.

tux4life commented: ...and then explain in detail what the program [B]if[/B] doing wrong... :P +15
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Enough, people. The facts are
1) fixed code should not have been posted by anyone other than the OP
2) fixed code should not have been improved by anyone unless the OP posted correct code in the first place.
3) People who expect the world to give them a free ride deserve the right to fail, and do not deserve the right to pass.

Now stop the flaming and get back on track.

tux4life commented: Finally! +11
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Your 1st half of the array array[x][0] is never initialized to zero so the values start out with garbage.

tux4life commented: Yes, that's the solution :) +10
Hiroshe commented: thanks +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

atoi() is portable itoa() is not

tux4life commented: Yes. +10
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

uRrite. Just another case of some turkey not caring that 100 pages in on a forum might be moot thread. Nothing better to do, obviously.

Salem commented: And it wasn't even a good post either! +36
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

nvm. going to ask teacher.

Smart decision. At least your teacher knows what the program is supposed to do and can ask the questions needed to help you.

tux4life commented: Good point :) +9
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I am always ready to answer your question, but not until you get a modern compiler that isnt gimped

Then stop replying posts you have no intention of of adding constructive responses to!

Adatapost, you do not have to use a jephthah-approved compiler.

kvprajapati commented: Thanks +5
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

what else am I missing, thanks for the help

Code tags --AGAIN!!!!

It seems that with the warning above, and the information posted all over this site about CODE tags, like
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used, even in responses to your posts
6) Even on the background of the box you actually typed your message in

you'd think one would get the message...

tux4life commented: Great! +8
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

C'Mon, people. Listen to what Midi is saying. He cannot -- repeat cannot -- make any changes at all to the software base of the computers at school. He does not have permissions. Therefore, any changes must be done at DaniWeb itself do he can utilize DaniWeb while at school.

Now, the question is -- is Midi using DaniWeb for school, or simply at school? :?:

~s.o.s~ commented: Haha :-) +28
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This has been answered so many times in this thread -- why are you still asking it?

Write to Stroustrup and ask him since none of the answers here seem to be acceptable and his book is causing your meltdown. His home page is http://www.research.att.com/~bs/ with an email address at the bottom.

tux4life commented: Good advice! +4
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

... what the difference is between condition and expression in these statements?

None. The condition simply evaluates to a TRUE/FALSE. Expression is a statement that will evaluate to a TRUE/FALSE. In the context of these loop definitions, they are interchangeable, and probably 'conditional expression' is more accurate.


[edit]Wow, a plethora of responses! We have no lives... :) [/edit]

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So any improvements ?

Yes. Stop using TABs to indent. Set your editor to use 4 SPACEs when the TAB key is pressed.

As for exiting, you can exit when ENTER is pressed all by itself.

And about Ctrl+C, look it up.

tux4life commented: I didn't know that about the TABs, I'll surely try it :) +4
Sky Diploma commented: Done !! Thanks :) +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

LoL, my mobile phone has a C++ compiler running on DosBox.

Jeez :icon_rolleyes:

:)

tux4life commented: Maybe he's just obsessed by C++ :P +4
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i'm just wondering, "where's the love?"

Good question. And from the person that posted:

  • i thought you were leaving anyhow? dont let the door hit you in the ass on the way out.
  • well, hell, i dont care really.
  • ...but i dont know WTF the OP is saying.
  • well, i was getting ready to reply, but then i got to that last part and just lost interest.
  • your reputation as "creepy internet stalker dude", just keeps getting more and more entrenched.
  • yeah, what do you know anyhow?
  • oh, look. here come more 5th graders.
  • come on tux, what we really should be talking about is why Crago3 has paternal abadonment issues.
  • that's about the most insensitive, presumptuous, short-sighted, arrogant and prejudiced remark i've heard in probably... well ... probably a day or two.
  • this is retarded.

I'm just sayin' :icon_wink:

nav33n commented: Spot on! +11
Ancient Dragon commented: good point :) +36
verruckt24 commented: He He...Look who's talking kinda isn't it. +4
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

He's counting his digits from right to left Walt.
So IMHO it has to be more something like this : (pseudocode)

number = 12345;
n = 4; //we seek the fourth digit from the right
num = number / 10^(n-1);
digitvalue = num % 10; //this we want

Interesting....
Dividing by 10, Mod'ing by 10. You just added the obvious power which was hers to think through. I tried not to take all the thinking out of the problem.

Salem commented: Yup, gotta make 'em think at some point +30
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes, what's your point?

Simply to verify my thoughts on the subject.

iamthwee commented: Bravo! +19
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It's perfectly acceptable to compare floats. You just have to understand the difficulties and know how to deal with them.

Because floating point is not exact, you need to define what precision is acceptable. If you want a .01 variance, simply test for it:

if ((inputValue > targetVal - 0.01) && 
    (inputValue < targetVal + 0.01))
{

Now if you input 5.0 and you get 5.00000001 your comparison works fine.

tux4life commented: Very simple and effective solution :) +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

But, I checked it in a C++ Book(*) before I posted these examples ...

(*) C++ Beginner's Guide by Herb Schildt, a free legal ebook copy is available here, so you can check the do-while if you want (Chapter 11, p31-p33) ...

So ol' Herbie is wrong, legal book or not. Publishing bad information has been know to happen -- a lot.

But if you use a do-while statement, the eof() check is always performed after the reading, so what's wrong with it ?

Yes, but you are processing bogus information before the eof() check . Did you look at the link I posted? Write your do-while loop and read the file described in that link. If it works, post it. If it doesn't, :icon_wink:

tux4life commented: Now I'm sure, It was confusing me a lot that in book x they're explaining this and on site y they just say that it isn't possible, but after your excellent posts I finally understand it :) !! +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I do not even know what question to ask............

Then expect an appropriate answer. Only a couple of us are psychic...

Ezzaral commented: :) +21
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hi I have just been looking at the tutorial section and noticed their is very little there.

[RANT] What is it about there/their/they're that no one seems to know that the words are not interchangeable! Are the definitions that ambiguous? [/RANT] :icon_rolleyes:

Ancient Dragon commented: You are right :) +36
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

isnt gets() almost the same as scanf()? im using it because it gets more characters than scanf().

Yes. See this and this. Stop using gets() !

C code works inside C++ right. we use C++ in class and i dont think thats a problem, for me.

Then write C++ instead of C. If you want to write C code you must follow the rules of C and stop arguing with those that know the rules.

aiight, dude. i'm tired of all this grabassery. here's standard c, that will actually work.

He finally got to you... Oh well. :icon_wink:

Salem commented: Saying "Noooooooo" to gets() :) +29
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hello everyone, I'm working on a small assignment where I am supposed to write the code for the itoa function char* itoa(int Value, int Base); without using any built-in functions, and where the returned value is allocated on behalf of the caller. Value being the integer to convert, and base being octal, decimal, or hex.

I found this rather simple implementation and I was hoping we could discuss it here to see if the changes I'm making are appropriate/accurate and etc.

OK, have a seat...
1) malloc() -- this will cause memory leaks on each call. Once the function returns, the memory address allocated is lost and can not be returned to the heap. Stick with the static char from the original code.

2)

for(int i=30; val && i; --i)
  {
    val /= base;
    buf[i] = "0123456789abcdef"[val % base];
  }

The first thing you do in the loop is remove the low order digit so if you pass in 2765 you would get back 276.

3)

buf[i] = "0123456789abcdef"[val % base];

This is a trick that I personally would avoid -- but that's just me. Create a char* with the character values.
Also, what happens if the base passed in is > 16? This line will cause a lot of trouble. You need to test for proper base range to protect the program this function is used it.

tux4life commented: Nice posting, nice advices to the OP :) +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Did you bother to read any of the requested information posted all over this site about CODE tags, like
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) on the background of the box you actually typed your message in

Salem commented: Indeed, well said +29
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This is a perfectly legitimate question for this forum. It's about reading special key sequences. The hardware is just a red herring in this case :icon_wink:


1B 5B 41 is called an escape sequence. In this case ESC [A . So...

When you read a 1B set a flag that remembers that an ESC sequence is being read.
Read the next char, verify it's 5B and forget it.
Read the next char, use a special switch statement for ESC sequences only which processes the arrow and whatever other sequences you deem necessary, and clear your flag.

jephthah commented: thanks for correcting +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need to define some arrays first. Then we might be able to help you.

You also need to format your code so we can follow the code. Don't instructors teach proper formatting techniques these days?

tux4life commented: You've got a point here :) +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ahhh, that's how it works! Thanks SOS

~s.o.s~ commented: you're welcome :-) +27
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Because we already got our grades and passed the course. You can't pass using our work. You need to pass on your own work.

Salem commented: Well said +29
tux4life commented: Well said :) +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So?

Salem commented: do ray me fa +29
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

it didnt have a very long lifecycle?
IE gets years and years...

And it shows :icon_twisted:

~s.o.s~ commented: LOL :-) +25
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What he's getting at is variables should be defined only in code files, the .C or .CPP files. NEVER put a definition in a header file. Only the extern goes in the .H file.

The guards are only useful when a header file is used twice during a single compilation. When you compile 2 separate sources individually, the headers files are processed as normal and each object file gets the definitions specified -- both sources will have currentpacketbeingsampled defined.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Here, let me help you with the gets()/fgets() question:
Click Here.

And I'm sure it's inevitable, he's going to do the same with scanf() , too, so:
Click Here too.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

OK, done. Now what?

Nick Evan commented: Haha +11
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need to change your increment:

case 5: //move forward x number of spaces
        int steps = commands[ ++cmd ];

This will increment before you load steps, getting the number of steps.

ohnomis commented: solver of pre-incrementing instead of post-incrementing +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
strcpy(input,"          ");  // You don't need to do this if your next 
                                   //    line overwrites the value
   	scanf("%s",&input);        // see this
   	fflush(stdin);             // see this
Prabakar commented: nice links +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

hay dear i need help for c prog...
i used <textcolor (14+128) ,cprint> commands to blink some text. befor i drow rectanngel and some circle as back image. but the text is not apper. if i closed the graphic mood, then it'll show. but i need kept the graphic back ground. & i wanna to know how to gave input text in graphic mood. bcz i tried <scanf> it's not work propely under d@ situation. i hv 2 used only c, for d@ task.
pls help me!

bye!

Hay dear, plz rd the rulz. Esp da 1 abt "Keep It Clean". d@ wil hlp. Da rst uv da rulz iz imprtnt 2.

devnar commented: Laughed out loud! :) +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

would please correct it for me and posted in this forum, It's been 4 hours I've working on this but it doesn't work.

All you have to do is count!!

#include <iostream>
#include <cmath>

using namespace std;

void Instructions();
float do_next_op(char op, float o, float
 CAV);
void startCalculatorProgram();

void main()
{[B]  1[/B]
	startCalculatorProgram();
}[B]  0[/B]

void Instructions()
{[B]  1[/B]
	cout << "Begin Calculater " << endl;
	cout << "Instructions are:" << endl;
	
}[B]  0 (so far so good)[/B]
float do_next_op(char op, float o, float CAV)
{[B]  1[/B]
	switch (op)
	{[B]  2[/B]
		case '+':
			return CAV + o;
			break;
		case '-':
			return CAV - o;
			break;
		case '*':
			return CAV * o;
			break;
		case '/':
			return CAV / o;
			break;
		case '^':
			return pow(CAV, o);			
			break;
		default:
			cout << "the input you choosed is not correct" << endl;
	}[B]  1[/B]

void startCalculatorProgram()
{[B]  2  (2?? This should be a 1! Something is missing above)[/B]
	Instructions();

	float accumulatedValue = 0.0;
	char op;
	float o;
Salem commented: Nicely put +23
Ancient Dragon commented: exactly! +36
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Now read the information
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) on the background of the box you actually typed your message in
to learn how to use code tags. It's not like the information isn't available and in your face. It's really hard to miss.

Salem commented: You forgot to add "don't provide complete answers on a plate in response to zero effort" +22
iamthwee commented: yup +17
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Good evening.....

I just wanted to share an idea.....can this forum be downsized into categories such as API,FORMS,CONTROLS,DATA REPORTS and so on.....the reason i am saying this is people are lost in here....

Who besides you is lost? Have you tried Hare Krishna...:icon_twisted: (see The Muppet Movie)

Nick Evan commented: :) +9
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

and I regard all of that with great respect.but honestly thats life and it wont change.let me put it this way
you're on youre way to buy a expensive sofware[witch they always are] and your geeky friend comes over and offer you a cracked version with no prob's to experience, are you going to reject him and go pay x amount?dont think so

Then you don't understand most of us. There are many people here with integrity.

I do understand you and feel for you.aunistly I usually use crack stuff

I'm sorry for you, then. No wonder the price of software is so high -- to make up for all the people stealing it. Thank you so much...

And, by the way, in English, there is always a SPACE after the period ending a sentence. English is not a web address.

sittas87 commented: I was a little silly.my apologies +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Lives in Philippines -- "be more pacific"! Ha Ha, that's funny!!!:)

iamthwee commented: i agree +16
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

my point is that STRSTR function will do what the OP wants

i thought it would be readily apparent to anyone who takes a moment to look it up. sorry, if i don't type out a fully commented and validated solution.

Not necessarily. Without knowing what needs to be done, looking up a function generally is not of much help. After your explanation, your solution is readily apparent.

I'm not really criticizing your recommendation, just that how you meant to use it is a good thing to add.

jephthah commented: good point. +4
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

WOW! 4 pieces of code to choose from! Which one works best? Which to choose to turn in as the assignment answer?

C'mon guys, we're here to help, not do everyone's assignments for them!

jephthah commented: word. +4
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The 4000+ guests! :icon_mrgreen:

~s.o.s~ commented: :-) +23
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

sms 2 me tht u hv a prblm. snc we no u so well, we sgst cndl mkg. its mch ezr thn cptr

Ezzaral commented: Excellent! +10
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

There no any reason on why do we have to convert it binary to hex. At at least i havn;t come across any application which need a that feature!

I have.

mitrmkar commented: same here ... +4
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Second problem is you are forgetting that the RETURN you type in is also a character that gets put into the buffer. Therefore, in this code:

cout << " Empezar?? " << "\n";         // TO START
	cout << "    1 - SI" << "\n";
	cout << "    0 - NO" << "\n";
	cin >> empezar;
	cout << "\n" << "\n";

	while (empezar != '0')      // IF I PUT THIS WITH '' DOESNT WORK. IF DONT, DOESNT TAKE IT
	{
		cout << " Ingrese lo que va a enviar: " << "\n";
		cout << "    3 - Carta" << "\n";
		cout << "    4 - Paquete " << "\n";
		cin >> a_enviar;
		cout << "\n" << "\n";

if you enter 0, empezar gets the value '0'
if you enter 1, empezar gets the value '1' and a_enviar reads the RETURN.
if you enter only RETURN, empezar reads the RETURN and since it's not '0' the loop is started.

Salem commented: Yep, good old character based input strikes again. +20
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It would be best to let us know what O/S and compiler you are using so we don't have to guess, as jephthah was forced to do. They all have different ways to accomplish the task.

jephthah commented: yup. i was just having a momentary bout of niceness :P +3