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

Kapow!!! Ezzaral the Conqueror Strikes!

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

Depends on many things like:
what's in the file?
where the file is?
is it protected?
is it encrypted?
is is broken?
is it locked?

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

use va_arg related macros

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

1) count the number of characters and when you hit your magic number output a \n
2) call srand() only at the beginning of your program, never in your function

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

Couple things I see:
srand() should be called once only -- when the program starts.
You call shuffle() for every card dealt. In a real game this means:
1) Shuffle the cards
2) Deal one card
3) Take the card back
4) Shuffle again
5) Deal one card again (which could be the same card)
6) Take the card back
7) Shuffle again
8) continue...

Rethink your deal...

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

just use system("pause") in the end before return

Search for this terrible function call on this board and learn why we do not suggest it.

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

Hi all,

I need help in the following problem.

I have a data file containing 100 columns, with different number of rows.

How can a file have a different number of rows?

I would like to read for example the columns from 45 to 56 and calculate something on these columns one by one, let's say calulate the mean value or make a histogram.

Could anybody help me how to do this?

What have you got?

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

hey everyone on Daniweb, I'm liuhh00 in need of some dire suggestions for my program.
I can't seem to solve why my program is not working right after i select my choice for case.

The program is suppose to accept any 20 random integers, store them and allow the user to tranverse as many as they would like to.

...

open to any critique as well. I am just looking towards improving the program's efficiency.
I am currently working to make the program run as long as user wants until they are ready to exit as well.

I use Codeblocks as my compiler.

Thanks!

When asking for help it usually works best when you describe the problem, not just say "doesn't work" and expect us to read your mind.

To post really excellent questions, here are some guidelines (since no one bothers to read the sticky titled "Read This Before Posting A Question"

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Then try reading the string twice. Once to clear the buffer, Again to actually read the input.

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

Of course you can. You'll have to explain why you think you can't.

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

You need to ask the question again. It's confusing.

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

When you enter numbers (like your doubles) the ENTER is left in the input buffer, since it's not a number. You need to clear it before reading a string or a character. Look into the cin.ignore method.

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

If it compiles 'perfectly' the files are in the proper folder. You should usually assume on a perfect compile that the error is with code, not the compiler.

After you enter a number, why shouldn't the program end? What statements are there to keep the program running?

I believe the correct description of your problem is that after you enter your time, the program seems to run but upon exit the window closes immediately so you can't see the answer.

Add a cin statement before the ending return to prevent the program from exiting immediately.

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

Excellent!

Nicely formatted (up until main() )
Commented (could use a few more but much better than most code here)
No glaring use if undefined behavior
And no conio.h!! Yippee!!!

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

And please don't yell at us.

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

It's the simple things that drive us ALL crazy. "You mean all I had to do is...???"

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

I can think of worse places to get stuck... :icon_twisted:

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

Now, I have to ask: just what do you mean by 'have it output'?

The message " ... have it output [B]what is going on[/B] in that function? " is to me clear. He wants to 'debug' the function and make sure the proper values are being generated. Am I mistaken?

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

That is not a tree as far as I can tell. 5 & 9 cannot be the child of 2 nodes. Unless you can explain how it works and I'm missing something.

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

What is the purpose of function with nothing in the parentheses? Like this something().

Many times the function is for input, and it simply returns the data entered (getchar() for example)
Other times it can load your class data from values saved on disk, for initialization or returning to where you left off in a game (more input)
Maybe it will initialize some hardware so you can access it

Lots of reasons.

Also, is there a way to write a function and then have it output what is going on in that function?

Use cout as suggested.

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

Yep... :icon_mrgreen:

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

Ah I see.

Though what i meant was get the same results of the infix notation as in
1+2-3 = 0 <- I can do this
1 2 + 3- = 0 <- I don't know how a computer evaluates this

A computer doesn't evaluate it. A program, written by you, does. You take your knowledge and convert it into a program (like the previous post).

As for your code, without proper formatting I'm not even going to try to follow it. It's hard enough understanding someone else's code without adding the difficulty of no indentation at all.

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

mi=forwardname.substr(space1pos+1,space2pos); is your culprit. Is the 2nd parameter the ending location or is it number of characters?

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

Not 100% sure what your saying. The code I put in the original post IS an infix to postfix converter. I know how to convert infix to postfix and prefix. What I don't know and am asking for is how to evaluate the postfix code like it was in infix notation in C++.

Confused. You can't "evaluate the postfix code like it was in infix notation". It's Postfix. Try giving an example. Words don't always do the job, especially when you aren't even sure of what you're asking.

As in I enter an infix notation equation, it's converted to postfix, and that post fix is evaluated. What I'm hoping for is an explanation on how, in C++, postfix is evaluated. I know the mathamatic way it's done I just can't express it in code.

If you know the mathmatical way, you need to
1) write down the decisions and steps themselves as a guide. This becomes your algorithm.
2) Now break each step/decision into smaller steps.
3) When the steps are broken down small enough, use the steps to evaluate a few equations. Make sure the steps are in the proper order to evaluate your equation.
4) This is when you can translate the steps into code. Just follow the roadmap you've created.

This is how programming is done:

Design (1), no computer involved.
Plan the process (2)
Verify the process (3)
Code (4), where the computer finally comes in.

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

I only put it red because I want to.

Please stop. We strive for professionalism, not cute.

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

Hi, I need to do a depth first search tree for the following undirected graph:

1-2-3
| | |
4-5 6
|   |
7-8-9

(Sorry about the graph being so unclear, the dots are just to space the lines out). It says to start at A which I'm guessing is 1?

My first attempt at the order was 1-4-7-8-9-6-3-2-5 but I'm really not sure?

Use Code tags to keep spacing.

That's not a tree.

Did you mean:

1-2-3
|   |
4-5 6
|    
7-8-9

Or in tree form:

___1___
     |       | 
   __4__     2
  |     |    |
  7     5    3
  |          |
  8          6
  |
  9

If so, it's 1-4-7-8-9-5-2-3-6
Your tree would be:

___1___
     |       | 
   __4__     3
  |     |    |
  7     6    2
  |          |
  8          5
  |
  9
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'd start by learning to format your code properly.
Then understand that main() has never been a void function. See this.
Further know that conio.h and getch() are nonstandard and should not be used. There are standard ways to do what you are trying to do.
And last, what makes you think strset() needs to be used. You only need a couple FOR loops for the entire program.

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

This is homework, isn't it...

If so, aren't you supposed to learn how to actually do postfix notation, and then be able to program it? First thing is to understand what postfix is, and how it works. Reading someone's code is not the way to learn it.

Do you need to find some good explanations on how to understand postfix and it's evaluation?
Start with http://en.wikipedia.org/wiki/Reverse_Polish_notation

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

The code below takes an entered infix and converts it into a postfix but I don't know how to take that postfix and evaluate it. Every single tutorial I've seen evaluates a postfix entered directly instead of a infix, so I have no clue what to do.

I don't understand the problem. Postfix is Postfix, isn't it? What's the difference between entering Postfix directly, or having Infix converted to Postfix and using that?

Think about it this way. If you're making spaghetti and you need tomato puree, does it matter whether you open a can of tomato puree or you open a can of whole tomatoes and puree them in a blender?

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

I need the code

Where on this site does it say we are a coding service to do your work for you?

This may help your understanding:

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And it does output...?
If you want help, you need to give ALL the details needed to understand the problem.

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

Change line 6 and 13. My psychic powers tell me the problem is there.

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

Open and Read

Write and Close.

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

is this program correct????????

Does it give you the correct answer?

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

Please fix your formatting.

Explain "not giving the correct answers". We aren't psychic.

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

I believe that 'i' is used in accordance with the rules of Hungarian Notion; a coding style used to self identify the type variables (int type vars use 'i').

Check out Hungarian Notation.

Nope. i has been used long before Hungarian Notation.

From Wikipedia:
"The original Hungarian notation, which would now be called Apps Hungarian, was invented by Charles Simonyi, a programmer who worked at Xerox PARC circa 1972-1981, and who later became Chief Architect at Microsoft. It may have been derived from the earlier principle of using the first letter of a variable name to set its type — for example, variables whose names started with letters I through N in FORTRAN were integers by default."

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

Why are there so many worthless posts here? The answer is extremely simple:

There is no function (why would there be?)
Use = on 2 consecutive characters.

Here's the answer plus it has a string function

We don't give answers here. We help them fix their attempt.

As for your code: main(){ -- main is always an int scanf("%s",string); -- see this for(i=0;i<strlen(string);i++) -- why calculate the length of the string every time through the loop? That's a waste of resources. And why compare the last character with the \0 at the end? if(string[i]==string[i+1]){ -- indent properly printf("%c\n", string[i]); -- indent properly
where's your required return statement?

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

hello everyone,
can anyone suggest me any software that is portable in pen-drive and c++ program can run in pen-drive.

I carry Borland 5.5 with me.

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

I want to make a table like this:

Seq. Name Class Seat VIP? Mileage(km)
==== =============== ===== ==== ====== ==========
1. Peter B 5A VIP 1046km
2. David F 1A VIP 2150km
......

Do I need to use for loop, strncpy to do so?
Or do I need to use some other methods?
I am learning objected oriented programming and I just know it up to strings, pointer, array.
Thank you very much!

Your best bet is to figure out how to do this on paper then figure out what code is needed to accomplish it.

Write down where you start from -- in detail (do you have data somewhere already? Where?)
Write down what you need to accomplish (from the starting point to the finish)
Write down what you want to have at the end -- in detail.

Now take that center statement and start breaking it down into tasks.
-- given the starting point, what tasks needs to happen to get to the finish?
Break those tasks into smaller and smaller steps.
When it's as small as you can get, look for clues to the functions you need.
Now, you can start coding.

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

I wasn't asking to get a dissertation on how time() works. (note my post count and Mod status -- I do know something :icon_rolleyes:)
It was to make the OP think about his question.

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

How do poker hands help in a blackjack game? A royal flush would be busted after the third card and never get the other 2.

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

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Two resurrections of a 3-year old thread with worthless posts are enough. Closed.

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

I now pronounce you student and guru. You may now Genuflect toward the great VD.

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

Don't us char, use string

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

Thanks doggyminder for your contributions,honestly i have already bought ebooks on adsense programs,i have also read so many free ebooks and reports on google adsense,but after creating so many sites,i discovered that what i thought was different from the result am seeing.

You seem to be proof that "you get what you pay for".

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

What do you think? ;)

I think ... you're letting your 3-year-old daughter answer the question! She's prob'ly smarter than any ol' bot anyway!

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

Get out some paper.
Start by listing all the reasons why and why not do this task.
Then if the why's win:

Write down all the functions your system must have. List as many as feasible.
Run through that list and choose 2-4 that are mandatory. List each of those at the top of separate sheets of paper.
Take each of those functions and
1) decide what sub-functions are needed to make this function work
2) break each of those down into smaller and smaller sub-functions
3) arrange those sub-functions into logical groups
4) Write the steps needed to execute these sub-functions, step by step

As you create these sub-function, write down the tks you have no idea to do, and add them to another sheet of paper. This sheet will become the "Things I Need To Learn" list. Don't worry about it yet if you don't know how to do something. That becomes part of the project.

Once you have designed each of your functions, design the 'global decision function' that can utilize/call each of your functions.

That's where you start. None of this should be on the computer, other than as notes. Do NOT write any code until you know what you are going to do -- in minute detail -- otherwise your project is likely to fail from poor planning.

Here's also where you can look into "The Things I Cannot Do Yet" list …

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

Put your cursor on the Do While statement.
Press F9
Run the program.
When it stops, look a the values of the variables. Are they correct?
If not, check to code to see why not, and hit STOP
If so, < press F8, check variables, repeat > until you find the error.

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

> Seriously, what is the difference between calling time() on Unix vs Windows?

Seriously? It depends. Entirely on the C library implementation that is being used.

POSIX requires that time() returns a 32-bit integral type holding the number of seconds elapsed since midnight (UTC) of January 1, 1970, not counting leap seconds since 1970. C/C++ implementations on Unix adhere to the POSIX specification.

On a non-posix system, using an implementation where the particular compiler vendor does not guarantee POSIX conformance, things are far more nebulous. The C standard itself doesn't specify anything more than time_t being an arithmetic type capable of representing calendar time. It doesn't specify the epoch; or for that matter that there should be an epoch at all or that leap seconds exist. It also doesn't specify the granularity of time_t other than that it is implementation-dependent. On one implementation, time_t could be a signed integral type holding one hundreths of a second since some epoch foo. On another, it might be a double representing seconds, with fractional milliseconds, since some other epoch bar.

Hence, the C standard also has:
double difftime( time_t time1, time_t time0 ) ;
"The difftime() function shall return the difference between two calander time values expressed in seconds as a type double."

And C++ felt the need to add <chrono>.

All well and good, from the internal development of the compiler. The question is will calling time() on Unix give a different time than on Windows? In other words, would Unix …