IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Well, interestingly enough
I get correct results when I do if (val1 < -127 || val1 > 127), but not when I do if ((val1 < -127) || (val1 > 127)). Which is strange; it's not what you'd think it should do.

val1 is an int.

The val2 in my earlier post was a typo when putting it into here; by that time I was getting squirrely.
--\n-------------------------------------------------------------------\n* Jack Troughton                            jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca]                   [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada               [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
New Re: Well, interestingly enough
Are you sure you're not using '|' instead '||' ?

Copy/paste the code...
--

OK, George W. is deceptive to be sure. Dissembling, too. And let's not forget deceitful. He is lacking veracity and frankness, and void of sooth, though seemingly sincere in his proclivity for pretense. But he did not lie.
[link|http://www.jointhebushwhackers.com/not_a_liar.cfm|Brian Wimer]
New Yes, I was sure.
--\n-------------------------------------------------------------------\n* Jack Troughton                            jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca]                   [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada               [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
New copy/paste the full code, then
--

OK, George W. is deceptive to be sure. Dissembling, too. And let's not forget deceitful. He is lacking veracity and frankness, and void of sooth, though seemingly sincere in his proclivity for pretense. But he did not lie.
[link|http://www.jointhebushwhackers.com/not_a_liar.cfm|Brian Wimer]
New Sure, here's my final version
\n/* Source file for the C program in Assignment 1 of CISC221 - Computer\n * Architecture, for Dr. Clive Dove. */\n\n/* Header Declarations */\n\n#include <stdio.h>\n\n#define SIZE 80\n\nint value1, value2, sum;        // variables to hold values entered by user after \n                                // conversion to numbers.\n\nchar instring[SIZE];    // String to hold number entered by user. Size is large \n                        // to ensure that there is no buffer overflow.\n\nchar error[20]; // string to hold error messages.\n\n/* Here there be function declarations. There are two functions; one to\n * convert an ascii string into an int value, and one to handle erroneous\n * input by the user. */\n\nint ascToInt(char []); // Converts ascii strings to ints.\n\nint inputOnError(char []); // Handles input outside specified range.\n\nint main()\n{\n\n        while (1)\n                // this loops until user puts sentinal value into value1 that causes program\n\n                // to exit.\n        {\n                printf("Please enter a number between -128 and 127.\\nEnter zero to exit:");\n                scanf("%s", instring);\n                value1 = ascToInt(instring);\n                if (value1 == 0)\n                        return 0; // Exit the program when user inputs 0 into first value.\n\n                printf("Please enter another number between -128 and 127:");\n                scanf("%s", instring);\n                value2 = ascToInt(instring);\n\n                sum = value1 + value2;\n\n                printf("%x + %x = %x, sum = %d, v = %d\\n", value1 & 0xFF, value2 & 0xFF, sum & 0xFF, sum, (sum < -128 || sum > 127));\n        }\n}\n\n\nint ascToInt(char *s)\n{\n        int result = 0;\n        int sign = 1;\n\n        if (*s == '-') // Test for a sign in the first character of the string.\n\n        {\n                s++;\n                if (!*s) // if next character is null, - is only character.\n                        result = inputOnError("not a number");\n                else\n                        sign *= -1;\n        }\n        while (*s >= '0' && *s <= '9') // while there are digits in the string.\n\n        {\n                result *= 10;\n                result += *s - '0';\n                s++;\n        }\n        result *= sign; // apply the sign\n\n        if (*s) // if there is anything other than a digit in the string.\n                result = inputOnError("not a number");\n\n\n        if (result < -128 || result > 127) // if result is outside of range.\n\n                result = inputOnError("outside the range specified");\n        return result;\n}\n\n/* inputOnError is the error handler for invalid input. It takes one argument\n * of a string indicating the nature of the error, prompts again for input,\n * and then uses the ascToInt function to value it, and returns the result to\n\n * the calling function. */\n\nint inputOnError(char *error)\n{\n        int output;\n        do\n        {\n                printf("The value you entered was %s.\\nPlease re-enter a number between -128 and 127:", error);\n                scanf("%s", instring);\n                output = ascToInt(instring);\n        }\n        while (output < -128 || output > 127);\n\n        return output;\n}


edit: I just wrote it... again:) This time I'm done 'cause after this I'm going to have a beer.

I'd esp. like to thank Todd for giving me the knife and fork and inviting me to dine.

edit2: took out my student number.
--\n-------------------------------------------------------------------\n* Jack Troughton                            jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca]                   [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada               [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
Expand Edited by jake123 Oct. 9, 2003, 10:27:30 PM EDT
Expand Edited by jake123 Oct. 10, 2003, 12:59:17 PM EDT
New Works with or without parens for me
VC 6 compiler

BTW, is it OK to criticize the code? Or would you rather hear from your Professor first?
--

OK, George W. is deceptive to be sure. Dissembling, too. And let's not forget deceitful. He is lacking veracity and frankness, and void of sooth, though seemingly sincere in his proclivity for pretense. But he did not lie.
[link|http://www.jointhebushwhackers.com/not_a_liar.cfm|Brian Wimer]
New Feel free
Do realise that certain things were written in stone... like the output.
--\n-------------------------------------------------------------------\n* Jack Troughton                            jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca]                   [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada               [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
New Re: Feel free
Well, you have a function

\nint ascToInt(char []); // Converts ascii strings to ints.\n


In reality, that function does nothing of the sort. It parses the string into integer, but then it checks that the integer is in range, handles the range errors, reads the string again (indirectly) an so on.

How about clearly separating string to integer conversion from reading, validation and error handling? See where that takes you.

--

OK, George W. is deceptive to be sure. Dissembling, too. And let's not forget deceitful. He is lacking veracity and frankness, and void of sooth, though seemingly sincere in his proclivity for pretense. But he did not lie.
[link|http://www.jointhebushwhackers.com/not_a_liar.cfm|Brian Wimer]
New You're suggesting that
I should break the function up two or three others?
--\n-------------------------------------------------------------------\n* Jack Troughton                            jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca]                   [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada               [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
New Basically, yes
Make the content really match the name.
--

OK, George W. is deceptive to be sure. Dissembling, too. And let's not forget deceitful. He is lacking veracity and frankness, and void of sooth, though seemingly sincere in his proclivity for pretense. But he did not lie.
[link|http://www.jointhebushwhackers.com/not_a_liar.cfm|Brian Wimer]
New Works here too, both ways. gcc 3.3.2
New It is working here
which basically means I screwed up somewhere, but since that version of the program is long dead (I wrote it about five times), I can't really go back and see where.
--\n-------------------------------------------------------------------\n* Jack Troughton                            jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca]                   [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada               [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
     I'm having a problem grokking C - (jake123) - (61)
         "\\0" is a string - not a character - (ChrisR) - (54)
             Re: "\\0" is a string - not a character - (jake123) - (23)
                 Double quotes is a string: - (ChrisR)
                 You want to use '0' not "0". - (a6l6e6x) - (21)
                     Thanks guys - (jake123) - (20)
                         sheesh, wackiness - (jake123) - (17)
                             operator precedence -NT - (deSitter) - (3)
                                 According to my text - (jake123) - (2)
                                     use "unsigned char" - (deSitter)
                                     Re: According to my text - (Arkadiy)
                             Should be equivalent indeed - (Arkadiy) - (12)
                                 Well, interestingly enough - (jake123) - (11)
                                     Re: Well, interestingly enough - (Arkadiy) - (10)
                                         Yes, I was sure. -NT - (jake123) - (9)
                                             copy/paste the full code, then -NT - (Arkadiy) - (8)
                                                 Sure, here's my final version - (jake123) - (7)
                                                     Works with or without parens for me - (Arkadiy) - (4)
                                                         Feel free - (jake123) - (3)
                                                             Re: Feel free - (Arkadiy) - (2)
                                                                 You're suggesting that - (jake123) - (1)
                                                                     Basically, yes - (Arkadiy)
                                                     Works here too, both ways. gcc 3.3.2 -NT - (scoenye) - (1)
                                                         It is working here - (jake123)
                         What is the type of 'value1' ? - (jb4) - (1)
                             Nah, it's an int - (jake123)
             NOT better! - (jb4) - (29)
                 Think we've had this argument before - (ChrisR)
                 Agreed -NT - (deSitter)
                 NOT boolean - this is C - (tuberculosis) - (25)
                     Re: NOT boolean - this is C - (deSitter) - (1)
                         Nah, put on your binary thinking cap. :) - (a6l6e6x)
                     Yes, yes...agreed - (jb4) - (22)
                         Breaking bad habits - (ChrisR) - (21)
                             Good points... - (jb4) - (15)
                                 Not that I do a tremendous amount of C programming... - (admin) - (4)
                                     K&R - (ChrisR)
                                     My mileage varies. :-) - (static)
                                     They are all ugly - (tuberculosis) - (1)
                                         Yep. - (admin)
                                 The business seems to have plenty of time on its hands - (ChrisR) - (9)
                                     Disagree with several of your premises - (jb4) - (8)
                                         Dude - (tuberculosis) - (7)
                                             Which reminds me - C++ is why our hardware sucks (new thread) - (tuberculosis)
                                             rofl - (deSitter)
                                             Heh - (jake123)
                                             Dude... - (jb4) - (3)
                                                 Whoa, JB gets feisty! - (deSitter)
                                                 Non-sequitur - (tuberculosis) - (1)
                                                     OK, then apology accepted........;-) - (jb4)
                             I'd have to agree - (jake123) - (4)
                                 Used to be a Fortran thing - (ChrisR) - (3)
                                     Re: Used to be a Fortran thing - (deSitter) - (2)
                                         Yep -FORTRAN for math libs rulez - (tuberculosis) - (1)
                                             Re: Yep -FORTRAN for math libs rulez - (deSitter)
                 Misra C guidelines - (ChrisR)
         Ob-C advice - (deSitter)
         Stylistic tip - (ben_tilly)
         Re: I'm having a problem grokking C - (tuberculosis) - (3)
             Hehehe - (jake123) - (2)
                 int isdigit(int c) { return (c >='0' && c <= '9'); } - (tuberculosis) - (1)
                     :) - (jake123)

Must be what keeps your hair up.
188 ms