Author |
Message |
nintendo64 Seasoned Helper

Age:39 Gender: Joined: Dec 01 2002 Posts: 104 Location: Dominican Republic Offline
|
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Fri Mar 26, 2004 10:41 pm Post subject: |
 |
|
|
|
Your file contains 3 numbers, but you want them broken out as single digits? There's lots wrong with your code, but I need more info on the results you want to help more. _________________ 4,691 irradiated haggis! |
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:41 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: Sat Mar 27, 2004 12:31 am Post subject: |
 |
|
|
|
Could I recommend either adding a Sleep to that, or to use a different function, such as _getch |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Sat Mar 27, 2004 12:21 pm Post subject: |
 |
|
|
|
Cyan~Fire wrote: | It is also considered better practice to declare the variables used in for loops inside the for declarator. |
I can't stress enough how much I disagree with that. |
|
Back to top |
|
 |
nintendo64 Seasoned Helper

Age:39 Gender: Joined: Dec 01 2002 Posts: 104 Location: Dominican Republic Offline
|
Posted: Sat Mar 27, 2004 12:46 pm Post subject: |
 |
|
|
|
Thx all for the help, i was just helping a friend with some applications in C/C++, he is studying mechanical engineering and he had some Computer Algorithms class using Borland C++ 6, and coding them in console apps.
The problem was his teacher didn't teach him most of the fundamentals he needed, they didn't taught him how to use Windows APIs or what they were(i know it's just simple include and use), how to read/write files, how to use properly for/while, and etc... and they wanted him to make for the midterm five projects, i don't know how the teacher expect him to do all that, if he doens't even understand properly the basics.
a Hangman Game
a Mastermind Game
a Clerk's Machine (the machine when you pay and give you your devolution?)
a Multiplication of matrixes (loading them from a file and then saving them to a file)
a Counter of letters (load a file then count letters from A-Z, spaces, including special characters like "á,é,í,ó,ú,ñ")
i helped him made mastermind, hangman and the multiplication of matrixes, the problem is i didn't know how to I/O in C/C++, tends my crappy looking code .
Well he just delivered his projects today, thanks for the help.
-nintendo64 |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Sat Mar 27, 2004 3:53 pm Post subject: |
 |
|
|
|
Ekted wrote: | I can't stress enough how much I disagree with that. |
So you say loop variables should be in-scope through the entire function, even if they're not ever going to be used again? Why? |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Sat Mar 27, 2004 10:24 pm Post subject: |
 |
|
|
|
Cyan~Fire wrote: | So you say loop variables should be in-scope through the entire function, even if they're not ever going to be used again? Why? |
When you are reading a function, you should only have to look in one place to find all local variables: the top. You could be inside a 4 page 3-nested for loop looking at the variable 'count'. You look at the top--not there. Maybe it's the outside for loop counter--not there. Maybe the next level in--not there. Etc. Having to search for where a variable is declared is bad. And allowing variables to be declared at different nesting levels allows for the possibility that the same variable can assume different types within the same function. This is very bad. |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sat Mar 27, 2004 11:49 pm Post subject: |
 |
|
|
|
Mr Ekted wrote: | [..]
When you are reading a function, you should only have to look in one place to find all local variables: the top. You could be inside a 4 page 3-nested for loop looking at the variable 'count'. You look at the top--not there. Maybe it's the outside for loop counter--not there. Maybe the next level in--not there. Etc. Having to search for where a variable is declared is bad. And allowing variables to be declared at different nesting levels allows for the possibility that the same variable can assume different types within the same function. This is very bad. |
So instead you look around in a 4 page 3-nested for look looking for what the HECK count does. You see where it's declared, but is it ever initialized? I agree with you on the type thing, but you will have to come up with a more convincing argument for the for loop declaration. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Sun Mar 28, 2004 1:29 am Post subject: |
 |
|
|
|
Variables are initialized/modified where they are needed. A for loop control variable is no different than any other variable. |
|
Back to top |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Sun Mar 28, 2004 8:41 am Post subject: |
 |
|
|
|
Cyan~Fire wrote: |
It is also considered better practice to declare the variables used in for loops inside the for declarator (right word?).
Here's an example combining the two:
for (int y = 0; y < 3; y++)
{
...
} |
| Does y get destroyed after the for()? Or can it still be used later on without declaring it again?
What is this thing about 'scope'? Surely a function should be be short, then the scope would be small anyway.
OT:
I notice some people do
fprintf(stdout, "Error: can't open file.\n"); | instead of printf("Error: can't open file.\n"); | When should each be used? |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Sun Mar 28, 2004 11:34 am Post subject: |
 |
|
|
|
Yeah I hate MS.
About the loop variable type thing, if the coder re-declares a variable with the same name but different type, that's just bad programming. Saying "Write good code so you don't write bad code" is a little redundant.
About printf() and fprintf(): The people who use fprintf(stdout, ...) either don't realize that printf(...) is the same thing or they think forintf() is somehow cleaner. |
|
Back to top |
|
 |
Jackmn Newbie
Joined: Apr 02 2004 Posts: 13 Offline
|
Posted: Fri Apr 02, 2004 3:55 pm Post subject: |
 |
|
|
|
One rather obvious mistake:
file = fopen("c:\matrices.txt","r");
should be
file = fopen("c:\\matrices.txt","r"); |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Fri Apr 02, 2004 6:28 pm Post subject: |
 |
|
|
|
Hmm yeah, that should've given a compile error. (No such escape character as \m.) Good eye. |
|
Back to top |
|
 |
|