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

Why does everyone think new is the way to create static arrays? What a waste of resources!

Use a 2D array, row=number dialed, col=letters:

char letters[10][4] = { {'-','-','-','-'},  //0
                        {'-','-','-','-'},  //1
                        {'A','B','C','-'},  //2
                        {'D','E','F','-'},  //3
                        {'G','H','I','-'},  //4
                        {'J','K','L','-'},  //5
                        {'M','N','O','-'},  //6
                        {'P','R','S','-'},  //7
                        {'T','U','V','-'},  //8
                        {'W','X','Y','Z'}}; //9
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

When you read using fgets() and the line is longer than the buffer size (or bytes to read) the next read will continue where the last read left off -- in the middle of the line.

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

So migrate to a real browser -- they're free! :twisted:

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

I have a question for a homework assignment. This is C, not C++ (sorry! i didn't know where else to go).

Maybe in the C forum? I pity the future... :icon_rolleyes:

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

What value do you expect

sizeof(char*)

to be?

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

Compare the beginning of the string with each of the 'commands' and when you get a match test the rest of the string for the parameter(s), converting the digits to numbers if needed.

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

Find the min/max. The one that's left is the median.

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

Depends on the compiler I suppose...

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

yup, that did it, but just so I have a better feel for it, I seed the random number algorithm thing and then thats the first number the algorithm uses...

No, the seed designates where within the list of random numbers rand() will start. Random numbers are not calculated, they are pulled from a huge list.

a. Why was I getting 8 for every random number when I didn't seed the random number generator/what 'seed' was the generator using in the algorithm before?

Because the default seed always starts at the same place.

b. what is time(0) ? is it the number of nanoseconds that have elapsed since the program was compiled or something? and what does the '0' parameter do?

Look up the time() function. It has nothing to do with nanoseconds...

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

You probably forgot to seed it.

In other words, you didn't use srand()

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

Thanks for assuming I didn't do a search but its ok, I forgive you.

Gee, thanks. And I forgive you for leaving out important information...

We didn't learn anything about strings in class yet so I can't do that.

Then you can't do it yet. Wait until you learn strings.

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

This has been answered so many times you should just do a search.

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

#1: See this about gets() #2: See this[/url] about reading a single character with scanf()/fscanf()

Read a character.
Use a switch to test if it's a TERMINATOR
If so, read next character 
[
   if it's a secondary terminator character read one more 
   [
        if it's a tertiary terminator
        [
            you've found the end of a sentence 
        ]
        else
        [
            you've found nothing...
        ]
    ]
    else
    [
        you've found nothing...
    ]
]
else
[
    you've found nothing...
]
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

for (int i=0; i<=0; i++) -- look carefully...

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

Read my post.

Tygawr commented: spam +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

CODE TAGS
... read any of the requested information posted all over this site about CODE tags, like
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) Even on the background of the box you actually typed your message in!

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

Before printing use an IF statement: if (lastCharEntered != 'p') print

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

So, then add all the input values.

If that doesn't help, explain again in greater detail.

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

My code needs to run a sum

How do you do that? What do you need to do to run a sum?
Forget C++ for the moment and explain the process to me...

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

Forget the new operator. You don't need it.

I have it somewhat ok, until the end where it's supposed to give the average. I tried a couple things but none of them gave me the right answer.

What's your definition of "somewhat ok"? If it doesn't give you a proper answer, what's OK?

I don't think I'm keeping track of the sum either.

How can you tell?
What do you need to keep track of a sum?
If I give you 5 numbers, can you keep track of the sum on paper?
If so, how did you do it?
Do the same thing in your code.

Think through the problem, then code. Don't code, then beg for help.

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

You can't assign a string to a float value. You have to convert the string into a floating point number. Look it up. Key word is convert

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

I wanted to write a program to check if string entered is a palidrome. I wrote a program but i get errors while compiling. Can anyone help me identify errors in the program.

Are we supposed to guess what the errors are? Or would you like to tell us?

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

Let's see if I got this right.
Your school banned system calls.
You want to bypass that ban and make system calls anyway.

Sounds to me like you are trying to do something they don't want you to do.
Do I have the facts straight?

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

But I'm working on 2 512x512 matrices and when I try to find the Correlation it produces a number like: 1.64643e-14 which is obviously wrong.. I have tried everything..

What is obviously wrong about it?

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

Is it Dangerous to Derive from STD? Specifically std::string.

As far as I know, no. That's why objects exist. You start with an object that does most of what you want and add more functionality to it for your specific needs.

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

I don't seem to understand the difficulty. Can you do the task without using a function? If so, why would a function cause a problem?

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

but also the questions asked in the HR round of interview

I agree it's used to weed out candidate that can program. The answer to give the HR guy is "of what use is finding the greatest of two numbers without using comparison operators? Do you recommend using convoluted programming practices in the code created here?"

This response shows you are thinking of the employer and you'd rather write straight forward code than obfuscated code.

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

Ugh! I may need to ask for some examples.

Or you may need to post some code.

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

Hope past experience isn't the expectation...

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

Sorry, misread...

Have you tried testing the return statii of the I/O to see if there were errors? That's usually a good first step. You're just blindly assuming everything is working correctly -- and clearly it's not.

You also might want to shorten your test. Make a new data file with 88 records and change the IF to 10. When you get that working, go back to the full file.

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

STOP YELLING AT US! WE'RE SORRY! WE WON'T DO IT AGAIN!!!!

Read the friggin' Member Rules! And this:
[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 …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The site hasn't been skinned yet, so it doesn't look like much. We don't really want to show off the raw site as folks have a tendency to focus on how it looks and ignore how it works.

Not the moderators (at least most of us are savvy enough to understand that)

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

You are making it so hard! The instructions are:

Write a program that takes integer input from the user and store into the array dynamically allocated each time a new element is added.

Note the wording: "store into the array dynamically allocated ".
Allocate a buffer of sufficient size -- once.
There is nothing in the instructions that says allocate a new buffer for each and every integer.

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

You can't open and close a file between each write and expect to keep the data being overwritten.
Move the write outside the IF.

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

Food for thought:
How many cards in a deck?
How many cards in a suit?
How many cards of a rank? (same pips)

Can you see a correlation between all these numbers?
Are the following mathematical operators useful in calculating these numbers? * / %

You can make the job easier by thinking through these questions and coming up with a new representation of your deck.

Next:
Once you deal a card, as Moschops suggests, you need to remove the card from the deck or mark it as used.

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

Just make the password a character array.

jember commented: you didn't even explain the whole thing. -1
zeroliken commented: to negate the downvote +8
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Keep a counter of how many houses you placed in the array.

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

Java, python, perl, c, c++, algol, pascal, basic, snobol, lisp, pl/1, cobol, bliss, etc, etc...

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

I've tried adjusting the modus for file reading/writing, but it did not solve the problem: the file copy is still stopped after 705 bytes.

Then you didn't fix the problem properly :icon_wink:

If I understand correctly, the difference in speed between fread/fwrite and getc/putc is the same?

You understand incorrectly. getc()/putc() is slower because it reads one byte at a time. fread()/fwrite() can read multiple bytes so it's much faster.

But isn't the getc opening the file each time it gets a character and then reopens the stream, in contrary to fread that would only need to access it one time? I think I'il try the fread/fwrite method in this case.

No, if getc() opened the stream every time you'd only be able to read the first byte of the file.

Assuming I find a solution to the EOF problem (probably using fseek, suggested by DeanM),...

Worthless and makes your code too complex. Just read a block, write a block, read a block, write a block... Keep it up until fread() returns EOF.

... will fread work correctly with really large files (e.g. 3GB +), as it would allocate an absurd amount of virtual memory if it does it all at once. Would it be better to do read/write every 50MB or so? Or should I depend it on the virtual memory available (and if so, how do I measure it with standard C functions)?

Read the file in small enough blocks that
1) it doesn't …

Graphix commented: Constructive! +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Try outputting the characters in hex just before the test, and which block was entered.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
if (isalpha(charValue))
{
    // charValue is an alpha
}
else
{
    // charValue is not an alpha
}

Returns TRUE if charValue is A-Z or a-z
Returns FALSE if not.

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

Hi all..
How i can make a report without using database.
Data can directly from the active form.

Thank you in advance

If the form has all the info for the report, just start outputting the info the way you want it.

If that doesn't help please give some details.

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

Ahhh, now I see the problem. I didn't look close enough.

... but it moves a line down every time it encounters a white space.

That's the definition of a read using >>. If you want to read a line you need something like getline() .

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

That's because you read the number from your input but not the NewLine you also pressed. Loop up cin.ignore ...

I'm surprised the _getch didn't do the same thing...

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

So where do you need the endl? How do you know when that spot is read?

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

But what is the point of dynamic memory for a single type?

Exactly...
For a single type, it's a waste to use dynamic memory. I can't think of any reason why one would need to dynamically create an int or float.

Do you mean if i were to declare an object with dynamic memory within a particular function it would be available within another function?

If you pass it to the function, sure...

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

out_stream<< next<< endl; -- what does endl do?

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

ok , i did that, but it's still doesn't recognise 'i' in the second for loop.

That's because you didn't define it in the second loop. You only defined i in the first loop.

(Yeah i know i shouldn't be using _getch(), i'll get around to sorting that out.)

Why "get around" to it? Just use cin.get() and be done with it...

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

Always use { } to make your code readable and consistent.
This then no longer will be a problem.