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

Not fair, deceptikon -- giving me rep and taking it back! Positive rep, even as a test, is a good thing! :P ;)

On a serious note, I hope you aren't planning on changing the wayt the box and arrows interract. I happen to like the way they work now.

Oh, and the comment you made was left in my list of rep even after you removed it. That might be a bug...

deceptikon commented: I'll return it to you. ;) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What type did you enter with scanf("%c",&option);? What's the binary value of the input?
What type did you compare with case 1:? What's the binary value of the test value?

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

this is a code from the book "the C programming language" by dennis ritchie

I'm looking at the code in the book right now. Your code doesn't look like the code in the book. They wrote the code with indentation so that it's easy to follow.

Look at the big IF statement. 2/3 of the statement is good, but 1/3 is wrong (it's wrong in the book, too). What do you see that's not consisent? I velieve if you look closer, there is either an error or warning for that line.

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

What is the result of 10 % 10? How can that answer be used to output the value you want?

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

I use the undo option when I decide I want to remove my vote, not because I accidently added a vote.

I still think it would be a good idea to change the dropdown (wording) to know if you've hover over an up or down arrow...

No it wouldn't. The comment I made above to the Good Reverend I hovered over the down arrow simply to open the input box. I then clicked the up arrow. I think it would be a bad idea to indicate which arrow initiated the box since it is immaterial. You can click the other arrow to save.

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

Or use getch() :twisted:

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

Look at it this way.

A declaration is like your street address. It isn't where you live, just a reference to the location. It simply says that your place (or the variable) exists somewhere.

A definition is the house/apartment itself. It holds all your stuff -- like a variable.

You can have your address (declaration) on letters, your license, in your bank account, many places. But your house (definition) can only be in one physical place.

int x; is the definition.
x = 10 is not a definition. It's an assignment. Like buying a new chair. It just goes into the space that's defined.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
>/*than it compares the two so:
>   0010100010001100100000000000
>                       10010110 |
>=  0010100010001100100010010110 
>*/

No.... Look up what a single | does.

>red = colour & 0xff
>
>/*than to get the last bits:
>      0010100010001100100010010110
>                          11111111 &
>                   red  = 10010110  

And a single &

And then word is then, not than ;o)

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

FYI, it would be easier to tell if the value was loaded properly if you print using HEX (%X) instead of integer (%u). Food for thought.

I have tried to make a chart of how the unsigned int should look at the end, if its wrong than my understanding of bitwise operators is wrong aswell :P :

Print in both Hex and Decimal to compare, see if there is any truth to your assumption/understanding.

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

@WaltP The way you showed me doesn't j++ so it would just keep replacing the same array

I wonder if there's a fix for that. I'm not going to do all your work. You still need to think. That's part of programming...

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

1) indent better so we can read the code easier. 3 to 4 spaces is normal.
2) print your code and grab another piece of paper and a pencil.
3) sit at your desk and start at the top of your code and start writing out all the variables (including string sizes) and follow your code step by step, changing variables values and drawing the arrows to where the pointers point.

You should then see where you are going wrong and, if you can't figure out how to fix it, you can ask a really good question because you can explain in detail what you saw happening.

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

Why don't you use the same technique i showed you for SPACEs, Numbers, and Punctuation? What I gave you was an example, not a complete answer. What if your 'sentence' is

Jonn Jonzz    2314 54th Street    High Plains, Mars --- out for lunch!!!
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

How about copying all of a type in one go:

    while (Block[i])
    {
        while (isalpha(Block[i]))
        {
            Token[j][k] = Block [i];
            k++;
            i++;
            Token[j][k] = '\0';  // be sure to 'end the string'
            Type[j] = 1;
        }

This will copy the entire word up to the first non-alpha character and leave you set at the following character.

A slightly cleaner option:

    while (Block[i])
    {
        if (isalpha(Block[i]))
        {
            k = 0;
            while (isalpha(Block[i]))
            {
                Token[j][k++] = Block [i++];
            }
            Token[j][k] = '\0';  // be sure to 'end the string'
            Type[j] = 1;
        }
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Refresh your cache...

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

1) you can't use strcpy(). You are dealing with substring and this function is for full strings.
2) look up the functions I mentioned. They will make your life easier. Unless, of course, you like to string 15 conditionals inside 1 IF statement.

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

Look you the is***() functions -- isalpha() isdigit() ispunct() etc...

They are in the ctype (or ctypes, I can never remember) header

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

for(string::const_iterator iter = s.begin(); iter != s.end(); ++iter)What does this line do?

string::const_reverse_iterator rit = s.rbegin();
What does this line do?

What do the variables defined (iter, rit) point to or indicate.

Why make pointer to the characters? Why not generate subscripts and just use them?

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

In your original description you said

Given number n ( n<=9999)

Inputting a string is not a number. You need to rethink your program and reconsider this suggestion.

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

Mike, he said:

The purpose is to create a brand new object each time the loop is executed for as long as the loop runs.

so he wants

while(/* .. some condition .. */) {
  // ... some code..
  create a DataType Obj;  // another object 'Obj' gets created here.
  // .. .some more code..
}; 
delete all objects

so if the loop runs 6 times, 6 objects get created. 20 times, 20 objects.

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

You need the header cstring for the C style function. string is for the C++ string object.

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

Look more closely at ("test\" (variable+".txt").c_str() ).
You are missing something.

It's usually better to create complex strings in pieces rather than all in one line like this. Once you get the string generated properly, then start combining the terms.

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

Of course it's giving the same seed. time(0) returns the current second. So, unless each call to srand() if over 1 second apart, the seeds are identical, giving identical random values.

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

We really can't get hung up on pos/neg votes. Over the past month I've been downvoted for

1) reversing my stance and stating I now understand a situation and agree with the decision here
2) answering questions that help the user here
3) explaining the details of a problem and showing exactly why it happens and how to understand it here
4) never having programmed a downloader task because of lack of interest here
5) Asking for clarification here
(none of which the voter was brave enough to leave a name/message - the cowards ;)

Of course some others were well deserved.

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

Then we obviously need more context. Like the function(s) that call this one, the one that opens the file, and the first few lines of the file.

And an exact descripton of what's going wrong with as much detail as you can provide.

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

Instead of

for ( int i = 0; i <= NumUsed; i++ )
{
    for ( int j = 0; j <= NumUsed; j++ )
    {
        cout << List[i][j];
    }
}    

try

for ( int i = 0; i <= NumUsed; i++ )
{
        cout << List[i];
}    
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not quite. After you input all the numbers, set min to arraySize[0].
Then you code should work fine.

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

Where are you dividing?

Just before those statements, output the values used to figure out the denominator. For example, for line 43, display i and a[i][i]
Now figure out what that value should be and why it is zero.

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

For Example:
char *c; c="END"; c="BEGIN"; No errors

"END" and "BEGIN" are by definition allocated sequential memory during compile time. Then c="END"; simply loads the address where "END" is defined into the pointer c. Same with c="BEGIN";. It's simply loading a new address into the pointer.

while int *d; d={1,2,3,4,5}; Gives an error

In this case you are attempting to load 1 thru 5 which are not allocated in sequential memory but are simply values and this syntax does not equate to a memory address.

Further:
"END" is defined as the sequence 'E','N','D','\0' by the compiler. But, where c="END"; is valid, c={'E','N','D','\0'}; which looks like it should be the same but is not, for the same reason above.

in fact to use d, an allocation of memory has to be done and then filling the array must to be through filling element by element while using c is so simple!!

AND ALSO, one an array of integers is initialized can't be modified except by accessing its element. But as in the above example string c is modified with no problem

As I mentioned, modifying the string is done by loading another string address into the pointer. The integers are not pointed to by a pointer.

To replicate the char *c; c="END"; c="BEGIN"; concept with integers would be:

char *int1 = {1,2,3,4,5};  // this would replicate "END"
char *int2 = {9,8,7,6,5};  // this replicates "BEGIN"
char *c = int1;            // this is …
Ahmed Sarwat commented: Thank you very much for your help and sorry for my late thanks +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You are using Turbo C++. You must quickly switch to standard Compilers, which are available freely in the internet.

Won't he fail the class by not using the compiler the instructor insists on?
And could you tell him what compiler other than Borland could possibly compile the posted code?

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

Then your file is not where the program can find it.

You are not testing for errors. If the program can't find the file, you ignore the error and read it anyway. Look up the file methods again and add error conditions with worthwhile messages.

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

Your indentation could be cleaned up but thats more of a style thing.

Actually, your indentation needs to be cleaned up. It's a readability thing.

You need to be consistent. See this

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

fflush(stdin); //this does not work why?

It's not designed to work. See this.

cin.get(); //this does not work why?

That's because of cin.getline(input,5,'\0');. You left stuff in the input buffer. Just use cin.getline(input);

But when I enter "45:45" I get 45,4. The last character is missing.

char input[5]; isn't large enough. When you read a length of 5, you get 4 characters and the terminating '\0'. Define it as input[10] to be sure. On the other hand, why not just use a C++ string?

Also, your formatting needs work. See this, too.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Set up an array with the values 1-MAX (array[MAX], MAX being 60)
set up a loop with index 1 to 20
    get random number from 0 to MAX-index
    use that number as index into array to store the next number
    loop from MAX-index to MAX-2 and shuffle all contents down 1 entry
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

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

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

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

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

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

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

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

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

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.