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

The correct form is:

(rand() % (max-min+1) + min;

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

Finally!! Congratulations!

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

JPGs are not stored by pixel, so adding 1 to any value would change a lot of pixels, not lighten 1. You need to look at the JPG format more closely.

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

Look at each character and convert to decimal. Easy peasy. strtoul() will take time and testing to understand, you can convert this by hand in 10 minutes.

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

It's a game he's hacking. He has 2 active threads on the exact same question and we're bouncing back and forth telling him the same stuff twice.

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

Look up the function toupper() and tolower().

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

Maybe algorithm = formula in this case.

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

Jason, Since this is the C forum, why all the C++ suggestions? Steer him correctly to C solutions.

nmaillet commented: Pointless post. +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need to look up what perror() actually does. It's not in the wrong place, you're just not using it for the purpose it was intended.

Also, don't use conio.h and getch(). They are non-standard and will cause you headaches when you get to the other 98% of the compilers that don't use them. There are standard ways to accept input that all C++ compilers have available.

And use a loop instead of gotos. It's bad programming practice to use them when there are better control structures available.

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

Loook up memcpy()

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

You have been told how, you have been given the resourses, you have even been given an answer you can use as a pattern. Your turn.

If you still want it done for you, I charge $100 an hour, minimum 3 hours for consulting work. Student rate $93.50 if you can prove you're a student. PM me if that's acceptable and we'll work out the details.

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

OK, here. It took me all of 45 seconds to do this. With your lack of skills, it would have probably taken you 15 minutes to do the same thing instead of whining and complaining for the past 17 freaking hours.

4B 50 7B F1 F4 F5 5E 50 7B F1 F4 F5 5E 4B 4B 4B
K  P  {  ñ  ô  õ  ^  P  {  ñ  ô  õ  ^  K  K  K

There's your translation. Enjoy. Now Mark this question solved.

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

yeah buy not all of the codes i have are there alot of them aren't on the chart

Bull. Every code is on that chart.
I guess it tells us something important.

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

anyways that chart some of the codes i have arent on there.

Doesn't that tell you something important?

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

You can easily do it yourself. Just look up those hex numbers in any ascii chart

i dont know how :(

Follow his link and figure it out. It's simple.

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

No, the compiler doesn't know. You told the compiler that the variable was defined somewhere else. That's all the compiler knows. It trusts you.

Its when you try to link the declaration with a definition that the linker finds your error.

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

If you read my post you could get rid of all that error fixing and handle the input of "53 is the number" which you claim is an error but all these cin.clears and cin.ignore()s don't handle at all.

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

Sure. Try This

I_m_rude commented: awesome sense of humour :) hahahahahahah i am dying :D +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Line 14 is a strtok(). Since when does strtok() print?

And I repeat:

How do you know it's not "model\n" or "model "?

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

Any ideas? Am I misunderstanding cin?

Yes.

Using cin.getline() reads the entire line so you don't have to worry about characters left in the input buffer.

Speaking of re-using cin, I've run into a couple of issues with that. Namely:

  1. I've been using cin.get() before the main function returns, to enable the program to pause so I can see the output. This works fine, until...

Remember, cin.get() reads a single character. When you get to a prompt that says "Enter a character:" and you type in 'A', how many keys do you actually hit? Therefore, how many characters?

  1. I use cin to get user input earlier in the program. If this is the case, the cin.get() at the end of the program won't do anything

Yes, it does something. It read a character from the input stream. See above.

I read that cin.clear() would let me re-use cin, but this isn't the case; if I have cin.clear() and then cin.get(), the program still doesn't wait for input at the cin.get().

That's because cin.clear() doesn't do what you read... Look it up at a reputable site...

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

At point 1 string str is "model"

How do you know it's not "model\n" or "model "? Neither of those will match "model". For that matter, how do you really know what is in str?

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

you can declare them on the same line... it looks cleaner

I disagree, but that's just programmer's preference...

coolikedat99 commented: I don't like the way it looks either (that is, putting it on the same line) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use loops and if statements.

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

The statements are undefined so the output is not guaranteed to be anything specific. Different compilers may produce different results.

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 you missed:

  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.
  2. Post your code. If we don't know what you did, how can we possibly help?
    -Use PROPER FORMATTING -- 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.
  3. Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
  4. 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?
  5. 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.
  6. Do not ask for code. We are not a coding service. We will help you fix your code.
    -If anyone posts working code for you, …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sorry, missed the first method and zeroed in just on the pragma...

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

Depends on what you need to do. If you want to use "pre-defined data types like java", use java. If you want to use C, you need to use the data types C has. Or find a third-party library, such as the one already mentioned.

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

Enter it into a temporary input buffer. Then move it into place in your array.

np complete: you can handle such number by linked list.

Major overkill. Since the numbers must be kept sequential, why do you need a structure containing and int and a pointer and all that code to insert/delete/traverse nodes?

A simple array is the answer...

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

I don't use VC at this time but doesn't VC offer a way to disable errors from the project/IDE settings? If not, that figures...

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

@np complete
What your idea does is make sure there is a decimal portion to the number. But 5.0 is a valid floating point number.

What the OP need to do is basically what NathanOliver describes.

I'm new to C++ (bet you guys don't hear that very often!!)

Nope. Never. :P
What I want to know is why everyone thinks they have to tell us that. It's bleeding obvious based on the question and the code!

Just realised that I'd still entitled this "bit of weirdness".

which is technically in violation of the Member Rules: "Do use clear and relevant titles for new articles". Use a title that give us an idea why you are posting. In this case "Testing Input Validity" or something like that would be a proper title.

That was with regards to "goto" that I was trying earlier; I looked it up and everyone seems to agree that goto is obsolete.

It's not that it's obsolete (it isn't). It's just bad practice.

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

I think you should try this approach too.

Where do you imagine he used it? Look at his code again... :rolleyes:

NathanOliver commented: I think he writes before he reads +10
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes, turn off the error message for the compiler. M$ has decided to rewrite the function, but since the function they wrote is not standard, they also decided to annoy us with their "we're better than the standard" attitude.

I_m_rude commented: hahaha! nice ;) +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It's not his code. It's someone else's code ;)

So? Does that make what I said wrong? :P

Follow Kwetal's advice. What are you trying to learn from this code?

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

It means strcpy() does not take 5 arguments as you tried to do with strcpy(winKey[1].key, '1','2','3','\0')

Look up
1) How strcpy() works.
2) Concentrate on it's parameters and how they are defined.
3) Look up how strings are laid out (their definition).

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

1) You don't -- this is the C forum.

2) Set insert mode off, set the cursor on the s, and type.

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

these small programs doesn't really need inheritence,

It does if

The main purpose of this example is to execute inheritance

It's how we learn.

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

It's what happens when you set up an array like int array[10] and use a statement like array[12] = 23;. There is no array[12]. It only goes to array[9].

In your case, "123" is 4 bytes, not 3. it's '1','2','3','\0'. You forgot about the string indicator.

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

You are generating the random number correctly, just not using it correctly.

1) You don't need all that preamble to set up seconds and call srand(). It's easier (and less confusing) if you simply replace lines 10-12 with srand(time(NULL)). Generating seconds is obviously confusing you.

2) You output a random number but didn't store it so you have nothing to compare your input with.

coolikedat99 commented: Thank you for 'leading me to the answer'. I do remember things much better when someone lets me do some thinking on my own. +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

cout<<'a'+0;?? You're kidding, right?

Standard way to do this is cout << (int)'a';

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

Don't understand. You mean the idiots that charge for bandwidth and disk space? Isn't it their servers and their internet connection? That was my main point. Spam was just an incidental. Reread points 1,2,3. No spam.

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

What would you do with the character if you read an 'A'? Do that with the '/' in the else then continue as normal since c now contains the next character.

read char
if '/'
    read char
    if '/' ignore rest of line
    if not '/' do your stuff with '/'
do your stuff with char
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not a good idea IMO.

1) Many (most) of us won't open attached files or linked images. We certainly won't watch a video.

2) As you pointed out, "It may require huge database and huge maintainence of daniweb server." Who's going to pay these extra costs?

3) You gave the solution already: "[upload] a video on youtube or someother websites and [paste] the link here".

And in concert with 1 & 2 above what about spammers that upload porn? Why should DaniWeb pay for all the bandwidth that was completely wasted?

happygeek commented: well said sir! +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Read it.

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

GUI means Graphical User Interface. It has nothing to do with triggering anything. It's all the pretty stuff in windows, like title bars, sizable windows, arrow cursor, menus, icons -- all the stuff people think a computer must have.

IMO, if you're such a rookie, you don't need to understand anything you currently asked. That comes later when you understand the language itself well. Then you can delve into this advanced stuff.

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

In slightly more detail:

putchar:

get the character parameter
output the character to the screen

printf:

get the format string
parse and analyze the string (not trivial)
find out that there's a CHAR format specifier
call the char output subfunction (as opposed to integer, float, octal, etc...)
get the character parameter
output the character to the screen

By the way, scanf() does the same stuff. Use getchar() for character input.

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

Oops. Missed that...

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

Too complicated. You can do this much cleaner and without the valid_input variable.

And just for future user info, if anyone puts a \007 in any output statements I have to use, someone's going to get strangled. It's an annoying practice from the user's standpoint.

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

You should avoid goto completely. After 30 years in C, I've never needed one.

Restructure your program to use one of the 3 loop structures.

As for why it executes twice, when you type your answer, how many keys do you actually press? What do you think is now happening?

[edit]
One more thing:
Why use an expensive function like scanf() to read a single character? getchar() is specifically designed to read a character without all the overhead.

It won't solve your double-execute problem, though...
[/edit]

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

Does it work?
If so, probably. Test it with a lot more data.
If not, no.

Please don't use getch() at the end of programs. It's non-standard and when you get to a real compiler, you'll have problems.

What to replace it with? Well, what does getch() do? What standard statements do the same thing? Use that instead.

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

4th option:
Make a zeroed array of 5,00,000 integers.
For every integer read, use it as an index into the array and increment that entry. When done, the value that's 1 was read once.

But shanki himanshu's solution seems to be the most efficient. It's a really slick solution.