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

Dani: Not just India. That's what I was taught to use too!

How long ago was that?

nitin1 commented: nice question ;) +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I was always for this particular solution.

I do find, though, that "Deleted Member" is a bit offputting. Any way we can keep the name on each post but with that small font, and change the poster level to "Deleted Member"? I've seen that format used to good effect and still accomplishes the request.

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

Why are we allowed to delete memberships now?

nitin1 commented: nice question :) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Do you know about functions? Assuming you do, I see some that would be very helpful:

1) int spanSpaces(line, index)
This will start at line[index], skip all 'whitespace' (look up the function isspace()) and return the index of the next non-space character.

2) int spanText(line, index)
Same, but skips all text values, for Label and Instruction. Are numbers allowed in the abel or Instruction? If so, isalnum() is the function to use, otherwise isalpha()

3) int spanNumber(line, index)
Again, same but skips numbers (isdigit())

Using theis idea, starting before INSTRUCTION you might do:

if current character (line[index]) is a space, 
    call spanSpace()
    store index in instBegin
    call spanText() with instBegin
    store index in instEnd
    copy the characters from instBegin to instEnd-1 into the instruction
If current character (line[index]) is a space, 
    call spanSpace()
    store index in numBegin
    ...

Just string the calls with appropriate tests before/after each call. You know what characters to expect after each field. Make sure they are there.

Of course you have to start with LABEL

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

And what happens when you input EXACTLY the same input?

----

this is like pulling teeth

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

In normal syntax, optional values are surrounded with [ ], required are not. And, for this discussion, # will designate one or more SPACEs/TABs.
What I understand then is you can have the following:

[Label] # Instruction # number1,number2 # [; comment]

So:
A label cannot be preceeded by # and is optional

An instruction must be
1) preceeded by at least one #
2) followed by at least one # and number1

Both numbers are required in the format number1 comma number2 (are spaces allowed?)

The comment is completely optional.

If this is not correct (there are other optional parts), please update using the above syntax.

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

The code is from the professor, so i assume she is right :P

In my classes, I never assume the professor gave good data. I assume they will throw in bad data to see if we can handle it. It's your call.

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

Card[nCards] is one beyond the array definition. Since you allocated nCards integers, your last available value is Card[nCards-1].

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

I don't understand the term "some sort of error". Post the error. Don't take a picture of it and link.

Also, I noticed that it didn't add quotations and curly braces automatically when I created the first one.

The .cpp file was completely empty so I had to add the headers in myself.

Are these problems? For most of us the IDE doesn't write the code for us. That's the programmer's job.

My first thought when I saw "...I had to add the headers in myself" was "poor baby"... ;o)
I've been adding my own headers for 30 years.

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

I've used malloc countless times, but as far as I know, reading and writing to memory that isn't expressly yours (which is in fact done by the malloc function) causes a segfault... So why doesn't malloc generate segfaults?

For the same reason when you fly to Pheonix and rent a car the cops don't arrest you for driving a stolen vehicle. It is yours for the duration of the rental. So the memory malloc() gets is yours -- you basically rented it until either the program ends or you call free()

...it sounds like you're questioning how malloc() works.

I read it more as why malloc() works... ;o)

deceptikon commented: I like that analogy. :) +10
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No. It needs to be in the project directory -- where the .EXE lives.

Using puts() -- BRAVO!!! Finally someone who doesn't use printf() :o)

Using main() -- Oops. main() is an int. Always.

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

I can't tell if you simply made an explanation of what you are going to do or there's some unasked question you need help with.

Please be clear when you post. Both of the posts in this thread are ambiguous at best.

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

Ahh, we're playing Jeopardy. OK.

The question is: How can I read the file and store student information?

Did I win?

-------------------

In answer to your non-question, looks like either idea would work...

I_m_rude commented: WaltP is WaltP! He can never change! :-D hahahaha... awesome :-D yes sir, ! you win +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Rather than trying to describe it, which you are doing poorly, show us!

Post a small example of the file (3-4 lines) and exactly what you want printed.

Come to think of it, all you've done is continue trying to describe things. But it also sounds like you know what to do. If you've got it, say "thanks". If not, ask specific questions about what you don't understand.

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

Probably. Compile as a C program and fix the errors. That's the simplest technique.

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

Search for the string.
Add the length of the string to the location found
Start printing.

If you want a better description, give us more information about your situation.

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

Care to give us specifics about the problem?

With the explanation you gave, the best answer is "then you did something wrong".

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

Ok here it is...made the necesseray adjustments. Still Not Correct :|

you really need to explain what happens when asking for help. Based on this statement we can't tell if
1) you now have compile errors
2) you now have link errors
3) your program crashes
4) it surprisingly prints the words to "Jana Gana Mana"

Every post needs to be explicit. Detail what the problem is, and where you think the error is.

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

from where you got that link ?

What he said! :o)

And secondly, You are nice, I was wrong when i said rude to you.

See? I grow on you after a while. Like fungus...

thirdly, Can i post my own written code for his/her help on this topic?

Let's try some logic here:

A) What grade will you get for doing his homework for him?
B) What grade does he deserve for you doing his homework for him?
Therefore:
C) [type your answer here :o]

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

It used to be a connotation that it was a gay colour (Lesbian?)

It's also a connotation of Royalty. Guess which was first :)

I thought lavender was gay. Good thing this isn't BruciWeb... ;)

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

1) You didn't say that. How are we supposed to know you wanted to use 1990's technology.
2) Why can't it be run on Borland?

Refine the search.

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

I guess theoretically. But in practice, it should compile fine.

After a test, I could not get a clean compile at all. But since it's undefined, I really don't care... ;o)

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

So if you changed your code to say (++a)++, your code would work in C++, but not in C.

No it won't. Pre- and post- incrementing the same value is called undefined behavior, therefore the result may be different on different compilers. The result is ambiguous. See this

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

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

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

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

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

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

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 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

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

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

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

Also printf() is a very expensive way to output a single character. Better to use putchar('*') because it's made specifically to output a single character.

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

Not bad...

Here are some possible things you could consider for improvements:

------------------
Because coinval is a #define it should be in all caps. And while you're at it, define the heavy and light values too:

#define COINVAL 2
#define COINHEAVY 3
#define COINLIGHT 1

Also, make the values for typeOfCounterfeit into #defines as well:

#define TYPELIGHT 'L'
#define TYPEHEAVY 'H'
#define TYPEANY   'A'

These changes remove the need to use hard coded values in the code itself and you can make modifications very quickly and accurately by not searching through the code.

------------------
The function gameInfo() might be better named gameInitialize()

------------------
If you want to limit the number of coins to 12,
1) test for invalid values
2) don't make the array dynamic -- it's a waste of time and you won't need the delete

------------------
At the prompt "Press (H) for heavy counterfeit, (L) for light\n and (A) for computer to decide : ", what happens if you press K, or h, or a? Test for valid values.

------------------
All but the calls at the bottom of gameGenerate() could be put into gameInitialize() since it's all initialization.

------------------
The calls to srand() should ideally be placed at the top of main(), and only once.

------------------
For the test of typeOfCounterfeit you can use a switch(). It would make that section of code more compact.
Another option to testing 3 possibilities for typeOfCounterfeit is …

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

This looks like a homework question, and a fairly specific one at that. It looks like something from a programming intro course/tutorial, not an algorithms course.

Probably very true, but we have a long-standing guideline that when you simply post requirements with no details, no questions, and no code you are seen as someone wanting us to do your homework for you. So you get what you get in the way of advice.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Calling main() from within main() would be an example of recursion, and not looping.

its not loop. Its just "calling the main function" we don't consider it a loop.

Actually, it's called a recursive loop, so yes, recursion is a loop.

A loop is a programming construct that repeatedly executes some code while a certain condition is true.

Which is exactly what recursion does.

But the rest of the information here (for the most part) is correct enough. You should never call main() as a function.

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

I like option 1. I don't need to automatically see comments, but when I want to see them it would be nice to have "show comments" only when there are comments.

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

Consistent formatting is the key. See this and refine your indentation. I believe this will fix your problem when you indent properly.

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

I'm not sure what the situation is in India where the original poster is from...

But you can bet the boxes are programmed using Turbo C....

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

Plus, there are also reasons why we have it within the actual post area instead of immediately below. The first reason is, at the suggestion of the Google guy, it significantly increases the click rate as opposed to being in its own box immediately below the post. Secondly, most short posts end up having white space immediately below the message because of the medium rectangle ad to the right. By putting this whitespace to use, we are able to reduce scrolling required on nearly all pages. If you look at this thread with ads enabled, for example, you'll see that by having the related article where it is, instead of immediately below the post, we're saving about six lines of scrolling.

Now that all makes sense. I withdraw my objection now that I understand the reasoning.

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

Yes, it's precision, and double is simply more accurate. That does not equate to bigger.

For example: double may be 56.42735816, float may be 56.42736 -- float is bigger.