tux4life 2,072 Postaholic

>and then why does this code in java prints 1?????
i 'm sorry i mentioned java in c forum..but here's my doubt!!

I think it's better to ask this in the Java forum.

According to your doubt: i=i++; , as the link in Dave Sinkula's post mentions:
it's an undefined expression, so the result can differ from implementation to implementation.
For example, on my and on your compiler your program gave the same output, but it isn't guaranteed that this program will produce the same output on every implementation.

tux4life 2,072 Postaholic

:$

tux4life 2,072 Postaholic

Edit:: Don't bother reading this.

No man, I DON'T THINK SO...
We cant write i=i++
as i =i; or can we????( in this case 0 will be printed on screen)
or as i++ ( i agree 1 shud be printed)
but still my question for the assignment that happens last..the value 0 shud go to the variable i in i=i++;and it should print 0 instead of 1...

>We cant write i=i++ as i =i;
I didn't say that, can you quote me the sentence?

I guess you didn't understand me, let's analyze it:
If you write i=i++; , then it first assigns the value of variable i to variable i, at this point the value of i is still zero (Step 1).
At the end of the expression, the post increment operator (++) increments the value of variable i with one (Step 2).
That's what I meant with saying that writing i=i++; is essentially the same as writing:

i=i; // ([I]Step 1[/I])
i++; // ([I]Step 2[/I])
tux4life 2,072 Postaholic

Edit:: Don't bother reading this.

Writing i=i++; is essentially the same as writing:

i=i;
i++;

and because it's the same variable here it's essentially the same as writing: i++;

tux4life 2,072 Postaholic

I don't fully understand your question, do you just want to overwrite a file on your harddisk?

tux4life 2,072 Postaholic

Another remark about your code: if you use getchar() to get the user's choice, only the first entered character is significant for the choice, for example when the user enters: 3287, your program will interpret this as choice 3.

tux4life 2,072 Postaholic

Yea..Thanks..and i think i can instead use getche(); or getch(); as well if i don't want to add that line..
Right!!?

Well, you could do that, but it's generally not recommended because getch(), getche(), and all those other functions which are part of the conio-library are unportable, which means that if someone else tries to compile your code and if your code makes use of conio, it could be that his compiler refuses to compile the code because it doesn't ship with the conio-library.

tux4life 2,072 Postaholic

getchar() will only get one character, which means that when you enter a character and press the ENTER button on your keyboard, the ENTER is not read (which means it stays in the input stream, available for the next read operation), so the following time when you invoke the getchar() function, an ENTER will be read because it was left in the input stream.
What you need to do is read the ENTER away from the input stream, right after you read the user's choice:

do
{
  printf("\n1. please print hi");
  printf("\n2. please print hello");
  printf("\n3. exit d programme");
  printf("\n enter ur choice");
  printf("\n");
  ch=getchar();
  
  [B]char c; // Added this line[/B]
  [B]while( (c = getchar()) != '\n'); // Added this line [/B]
} while(ch!='1'&& ch!='2'&& ch!='3');

EDIT:: I changed the above code to read everything after the user's choice away, until a newline is encountered.

tux4life 2,072 Postaholic

What??? i cant get u

Well, if you can't get me, then you probably can't get someone else who's trying to help you, so it's probably the best that you don't waste your time here.

In order to get help, you first have to help us to help you, you can do this for instance by using code tags.

Information about code tags is spread all over the website:

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) Even on the background of the box you actually typed your message in!

tux4life 2,072 Postaholic

Some important things you should pay attention to:

Salem commented: Works for me :) +36
tux4life 2,072 Postaholic

To the OP:

Can't you read? You were asked to use code tags, but what do you do? You just continue to not use them, don't expect much help then.

Information about code tags is found all over the website:

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) Even on the background of the box you actually typed your message in!

How can you miss these? You have no excuse for not using them.

Your begging and begging and begging is really getting on my nerves, it won't get you anywhere, already bothered to even look at the links in Salem's post? Wait... Let me guess: no. And let me guess again for the reason: you didn't see any code in his post.
You're just another one who just wants us to fix up your screwed code.
Do you really think that we're going fix the code for you? We've better things to do, for example helping people who deserve help, in other words, helping people who are not like you.

To help you I'll give you one magical link …

tux4life 2,072 Postaholic

>I wonder if it's pos.
Well, just try it then.

tux4life 2,072 Postaholic

>And, I don't understand the reason why you initialise multipy as a string with 2 characters?
Each character string needs a null-terminator.
But I too see no point in using a string here.
It would be better to just use a character variable instead, but I would just directly compare with the operator, no variables needed then.

To the OP:
Instead of reading the whole line, and then doing a risky conversion, you could simply do the following to get the whole input:

double operand_one;
double operand_two;
char operator;

cin >> operand_one >> operator >> operand_two;

But this is not the 'perfect' way, the 'perfect' way would be: just get the whole string, and parse it, but I guess you aren't at that level now.

Could you also please explain me why you need a vector?
(I don't see any place in your post where you mentioned that it was a part of your assignment to use vectors)
And why you include unnecessary header files?
All these include directives are unnecessary if you use the above approach to get the 'expression':

#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cstring>

And if you continue using you approach, you can still remove the following lines:

#include <cstdio>
#include <cstring>
VernonDozier commented: Good advice. +21
tux4life 2,072 Postaholic

For an interpreter you could maybe take a look at this:
http://www.ddj.com/184408184

(in fact it's in C, even rusted (old) C, but you could maybe adapt some things from it)

tux4life 2,072 Postaholic

>This code compiles without errors or warnings but it will not produce an 'exe' only a '.o' file, firstly what is a '.o' file?
A .o file is an object file, when the compiler compiles the source code, it will generate such a file, most of the time, after the source file has been compiled the linker is directly executed/invoked thereafter, the linker will 'link' the object file to an executable file (under Windows, this file will have a .exe extension).
(Some compilers generate a .obj file instead of a .o file, just remember that they're both object files).

Also, read this and fix your code.

tux4life 2,072 Postaholic

Because I want to reuse some part of another project(not my code), and when I copy and paste related part, compiler gives the error "<vcinpl.h>" and somehow it is compiled in original project. By the way, I am using Visual Studio 2005.

Sorry but I get a Syntax error here when I try to figure out what that means :P

tux4life 2,072 Postaholic

Put this line on top of your program: #include <miracles.h> There's no point in what you want, however it's possible: just copy all your header files into your compiler's header files directory and it should be possible then.
But remember that there's really no point in doing this, it's even unpractical: everyone who wants to compile your code, has to copy your header files into his compiler's header files directory, and imagine what could happen when you create a header file which has the same name as a standard header?

tux4life 2,072 Postaholic

Just to avoid mistakes, can you try it with a simple marquee tag?
For example: <marquee>TEST</marquee>

tux4life 2,072 Postaholic

>you wont need it because filenames don't contain spaces in them and you are using it for files.
I can create files on my computer which contain spaces in their filename, so in fact to be fully correct you'll need it.
But you're right in saying that the getlin() has to be getline() of course, remember that it is code `à la Ancient Dragon´ :P
(not an insult)

tux4life 2,072 Postaholic

>when i made it live its not working
By reading that, I assume that you've uploaded it to some kind of online hosting provider.
Can you also give us a link where we can reach that particular webpage?

tux4life 2,072 Postaholic

Why do you think the code you posted does not work?

Because he is using an old compiler, as you can read in his other thread about the same subject:
http://www.daniweb.com/forums/thread205600.html

tux4life 2,072 Postaholic

>Also, shouldn't you have used cstdio instead of stdio.h ? I read somewhere that the .h at the end becomes a c at the beginning of the name in C++.
Yes, what you mean is that you've read about new-style headers.
In fact you may even just leave that line out, it doesn't make any sense in that code, and I even can't find a reason on why it slipped in there :)

tux4life 2,072 Postaholic

Did you dynamically write the <marquee>-tags to the webpage by using PHP?
How is the output? The same as the expected output, but just without a marquee?

tux4life 2,072 Postaholic

>thank you...hope you can help me with this... I need it tomorrow...
Well, I can only help you if I see the code you have so far.

tux4life 2,072 Postaholic

hai dani.

can u pls help me how to create piechart in c.

thanks in advance

Try it yourself first, and read this:
http://www.daniweb.com/forums/announcement8-2.html

tux4life 2,072 Postaholic

The fact is, you can't just do that, it's impossible, once you write: char streng[]= then you'll have to follow it by a string (something between double quotes), otherwise the compiler doesn't know how many bytes he has to reserve for the character array.

If you want to copy the contents of a C++ string inside a C string, then you can't just use the assignment operator (=), if this is what you want to do, then you should take a look at the link in my previous post.

tux4life 2,072 Postaholic

I think you're looking for something like this:
http://www.daniweb.com/forums/thread193208.html

tux4life 2,072 Postaholic

All what I need to know is: what do you expect this instruction to do: char dword[] = word; ?

tux4life 2,072 Postaholic

To the OP:
It would be better that you chose a better thread title in future, a title like "need help.." is useless, because pretty much everyone which opens a thread here needs help.
Try to be more descriptive the next time.

tux4life 2,072 Postaholic

This is an invalid line of code:

char dword[] = word;

What were you trying to achieve?

tux4life 2,072 Postaholic

There's no point in having a bitset if you're doing the whole conversion manually, if you've a bitset, and you want to convert the value in the bitset to an unsigned long, then you could just use the to_ulong() method.
You can find more info about this method here:
http://www.cplusplus.com/reference/stl/bitset/to_ulong/

(it would not have been part of STL if there wasn't an easy way to do it :P)

tux4life 2,072 Postaholic

Just look at this page: http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx
Explanation + examples.

tux4life 2,072 Postaholic

>what to do now?
I'm not familiar with old compilers, so I really have no idea.
Have you tried to use old style headers, for example: #include <fstream.h> instead of #include <fstream> ?

tux4life 2,072 Postaholic

Can't see any changes. It still doesn't compile and I get the same errors. The GNU C++ Compiler.

Probably because you're on a Mac then, Windows and Mac handle a newline in a different way.

tux4life 2,072 Postaholic

>well i compiled it before and after you told me and it worked perfectly
Sorry buddy your rubbish doesn't compile, what compiler are you using?
BTW, why so much global variables, ever heard of local variables?

Your code compiles with me, after removing #include "stdafx.h" and moving this block inside main:

do {
  ++i;

@23.12.2012:
Could it be that you didn't click: Toggle Plain Text before you copied his code?
I suggest you to not spend any word extra on him.

tux4life 2,072 Postaholic

cin.clear() is for throwing away 'enter' (the button you pressed to enter the file name)

Uh?? cin.clear() is used to set error state flags.
And...What has the ENTER-key to do with this?

thank you for the code but my compiler does not accept 'string' data type

What dinosaur compiler are you using?
Wait, I guess: Turbo CrapCompiler++ (yes, that's it's full name :P)

In that case there's probably no other way around than just using character arrays.

But the best thing you could do is: get a decent compiler.

tux4life 2,072 Postaholic

Hmm... if the range is 1 - 5 (5 included), shouldn't we use choice > 0 && choice <6 or choice > 0 && choice <= 5 ?

Oops! Yes, I thought there were only 4 options, you are right.
Thanks for the catch :)

EDIT:: I said it that way because the OP asked it in that way.
(So according to that block of code, when I saw it, I automatically assumed that there were only four options :D)

tux4life 2,072 Postaholic

tux4life,
I appreciate your time. I guess, from the OP's post that he/she has old compiler.
>include string.
-- is unnecessary when we include iostream and imports std namespace.

Well, to be honest I've never used an old compiler, so I couldn't know that, but I guess you're right.
(Hey OP, do you use an old compiler? Then I strongly want to suggest you to get a decent compiler, or: why not directly get a decent IDE: Code::Blocks for example; If you are using a modern compiler, then you may ignore this. (Please note that Turbo C or Turbo C++ are not categorized under modern compilers))

tux4life 2,072 Postaholic

To start: a foreword on the use of gets()

char name[100];
ifstream infile;
cout<<"Enter filename>>";
gets(name);
infile.open(name);

this is my code segment that is not working. i suppose i am missing something

Damn, how could I have overlooked this: gets(name); To the OP, and everyone else who still uses gets to get user input: don't use it anymore, C++ has a beautiful I/O class library which doesn't have the 'bad things' which the gets() function has.
gets() can just allow an array overrun, what if the user enters more than 100 characters ?
Remember that gets() isn't very intelligent, and it will act in a very bad way then: it will just start writing in some memory which doesn't belong to your program anymore, on modern OSes, you have luck, and the OS will be able to prevent the program from damaging and messing up the whole thing, but if your OS doesn't offer memory protection for example, your program will be able to crash the whole operating system if the user would enter more than 100 characters.
In C++ you could for example do: cin.getline(name, 100); or cin >> setw(100) >> name; (but you'll have to include the iomanip header if you want to use the setw manipulator to lock the upper limit so that cin won't overflow the array)
But just to make it yourself easy, use the string class to store user input, you don't have to worry about array overflows then:


       
kvprajapati commented: Proff. Tux teaching. +7
Nick Evan commented: A cookie for the effort :) +22
Tom Gunn commented: good +7
tux4life 2,072 Postaholic
int main()
{
  HTMLPage& page = google("CTreeCtrl background image");
  page.select2nd(topic);
}

Or, in case the OP doesn't understand: Google is your friend! Use it!

tux4life 2,072 Postaholic

Although, I have to admit... I don't fully understand why do I need this.

while (choice < 1 || choice > 5);

If I change it to like, "choice > 1 || choice < 5" then it stops working. But that seems more logical, doesn't it?

>Although, I have to admit... I don't fully understand why do I need this.

while (choice < 1 || choice > 5);

Well, this way works because: if the choice entered by the user is a number, lower than one, OR a number higher than five, then the choice is invalid.

>If I change it to like, "choice > 1 || choice < 5" then it stops working. But that seems more logical, doesn't it?
I know what you mean, if you want to have it work in that way, then you have to replace the logical OR by a logical AND, so that it becomes: choice > 0 [B]&&[/B] choice < 5 (I also changed the one to a zero here).
(Because the number has to be higher than zero AND lower than five, it's not enough that just one of these conditions is true, they must be both true).

tux4life 2,072 Postaholic

Welcome to the wonderful world of DW, I hope you like your stay here :D

Sure!! It became a new hobby of mine.

tux4life 2,072 Postaholic

I think everyone should just revert to DOS 6.1.
I mean, can you honestly recall the last time your pc crashed/froze/failed while running DOS 6.1? :) Exactly

Well, if you find DOS so good, why didn't you post your reply from DOS then?
I can give you a small app which will bring down the whole OS in less than a sec, try this under one of the NT-based OSes of MS, and the OS will just terminate the app.

DOS doesn't offer any memory protection, is very vulnerable to viruses which just wipe out your whole HDD.

Also it doesn't offer multitasking.
(well maybe you don't need it)

etc.

Enough reasons to not run it.
(Even for the old DOS games it is not very suitable anymore, unless you have a DOS machine, you could just run DOSBox (a dos-emulator) on your computer)

Can you imagine what would happened when they had sent Apollo 11 to the moon running everything on DOS?
(I can: The rocket would probably never came back :P)

Menster commented: For taking your choice of OS more seriously than most people use choosing their religion. P.S you should probbably take a vacation +1
scru commented: now *this* is being a dik. -1
Aia commented: Because everyone is entitled to his/her own opinion. And not necessarily need to keep it for herself. +17
tux4life 2,072 Postaholic

Tomtelaw, you forgot to add the following line to your code: #include <string> :P

tux4life 2,072 Postaholic

Could you post your own try first?

tux4life 2,072 Postaholic

>I still think you need the +1 which makes the answer
30.89, which rounds to 31?

Uh? My output is 30 not 31, when you round it, you don't have to add 1 anymore.

2^31 = 2147483648
[B]2^30 = 1073741824[/B]
2^29 = 536870912

According to this ^^ I would say that 30 is the correct answer.

EDIT:: Yes, you're right that rounding may not be the best way for doing this, adding one and casting to an integer would be better.
It was just a coincidence that ceil worked here :P

tux4life 2,072 Postaholic

ALI INAM, you should urgently stop posting such rubbish solutions, BTW: why making every variable global?
Ever heard of local variables?

Do you really think the OP will learn from such solutions?
By just giving code to the OP, you won't help him, remember that.
It's against Daniweb's homework policy.

Links for (I hope) a permanent reminder:
http://www.daniweb.com/forums/announcement118-2.html
http://www.daniweb.com/forums/announcement118-3.html

tux4life 2,072 Postaholic

Logarithms should work as well because you can just derive it to search a power of two.
But, instead of the +1, why not round it?
BTW, iamthwee, you forgot a zero at the end of the number, that makes your output incorrect, it has to be one billion.
(eight zeroes instead of nine)

I would fix it to:

#include <cmath>
#include <iostream>

using namespace std; 
int main ()
{
   cout << ceil( log ( 1000000000.0 ) / log ( 2.0 ) );
   getchar();
}

I guess the output (30) is correct now.
(Solved it by hand using Windows Calculator :P)

iamthwee commented: Good catch on spotting the billion err +22
tux4life 2,072 Postaholic

Hi tux4life..

Thanks for reply..
I had try another code like below..

CString sz;
unsigned int test = 0xB0FF0000;
sz.Format("%x", test);

Then I got the result sz = "b0ff0000"..
but the sz value that I got is different than yours one..
means the code is wrong..??

Can you please guide me, where are my mistake is..??

Thank you..
shizu..

No, now there's nothing wrong with your code.
Your code is working fine now.
The value I said was the equivalent decimal value for the hexadecimal value you used in your code: 2969501696 and 0xB0FF0000 are both the same, except that the first one is in decimal, and the second one is in hexadecimal.

tux4life 2,072 Postaholic

Just throw it in a loop, create a temporary variable and initialize it to 1, and as long as the value that variable holds is lower as 1 million (or whatever other value you want to take as indicator of being a millionaire, be sure to use the number of pennies equivalent to this value in dollars here!), you multiply the value in the temporary variable by two.
(You can even use the << operator here)

You'll need to declare two variables before the place you put the loop:
one variable for holding the number of weeks it takes to become a millionaire, and one variable used as 'temporary' variable to let the loop decide whether to run another time or not.

When the loop has finished, you print out the variable holding the number of weeks, and you're finished.

EDIT:: Depending on how you implement the loop, you need to print the value of the variable which holds the number of weeks, plus one.