To: "Michael T. Smith" Subject: Re: More of my stupid programming mistakes? From: pfulmek AT email DOT tuwien DOT ac DOT at (Paul FULMEK) Reply-To: pfulmek AT email DOT tuwien DOT ac DOT at Cc: djgpp AT sun DOT soe DOT clarkson DOT edu Date: Tue, 23 Aug 1994 10:21:48 +0000 >>>Return-Path: >>>Return-Path: >>>Date: Mon, 22 Aug 1994 21:03:16 -0300 >>>From: "Michael T. Smith" >>>Reply-To: "Michael T. Smith" >>>Subject: More of my stupid programming mistakes? >>>To: djgpp AT sun DOT soe DOT clarkson DOT edu >>>Mime-Version: 1.0 >>>Content-Type: TEXT/PLAIN; CHARSET=US-ASCII >>> >>>I have been having more trouble with my conversion program. This time I >>>am almost done and have just a few (but still major) errors to clear up. >>>There are two of them: >>> >>>1. Converting from Binary to hex, decimal and octal doesn't work for me. >>>If I enter a relatively small number like 111000, it converts it to >>>"111000 Dec", "111000 Octal" and "111000 Hex" (or something along those >>>lines). If I enter any binary number that is much larger, it always >>>converts it to something like "4267267 Dec", "377777777 Octal" and >>>"FFFFFF Hex". It must be something to do with strtoul, which I don't have >>>quite figured out. >>> >>>2. The Conversion Table, listing Oct, Dec and Hex equivalents to 255 Dec, >>>doesn't work right. The Hex numbers are right, but the others are wrong: >>>Oct Dec Hex >>>----------- >>>73170 334848 0 >>>73170 334848 1 >>>73170 334848 2 etc. >>> >>>I have included the functions in question. Any help for this clueless >>>newbie would be appreciated (why am I having so much trouble with C???!!! >>>I know that there are supposed to be errors, but this seems to be an >>>all-out attack!). >>> >>>/* convtable() gives a listing of equivved Bin/Hex/Dec/Oct numbers. */ >>>/* SUN//14/08/1994//1629+ */ >>>/* Originally, I was going to put in Binary numbers too, but that would >>> take far too long, because I wouldn't be able to do a nice quick loop. >>>*/ >>> >>>void convtable(void) >>>{ >>> unsigned int convindex; >>> char hitkey[3]; >>> FILE *toprn; >>> >>> fpurge(stdout); >>> ScreenClear(); >>> >>> printf("Please turn PRN on and on-line, and then press ENTER..."); >>> fpurge(stdin); >>> gets(hitkey); >>> toprn = fopen("PRN","w"); >>> ScreenClear(); >>> fprintf(toprn, "Octal/Decimal/Hexadecimal Equivalents\n"); >>> fprintf(toprn, "Oct Dec Hex\n"); >>> fprintf(toprn, "-----------\n"); >>> >>> for(convindex = 0; convindex <= 255; convindex++) >>> { >>> fprintf(toprn, "%o %u %X\n"); >>> } >>>} >>> >>>/* binconv() is Binary to All conversion. It is not with the rest of the >>> "connies" because it is a fairly late addition, 08/08/1994 >>>*/ >>>/* MON//08/08/1994//2030+ */ >>> >>>void binconv(void) >>>{ >>> char binary[33]; >>> char hitkey[3]; >>> char *other; /* I don't completely understand strtoul(), so I don't >>> know what this should be called! >>> */ >>> >>> fpurge(stdout); >>> ScreenClear(); >>> printf("\nEnter unsigned binary number (up to 32 bits long): "); >>> fpurge(stdin); >>> gets(binary); >>> printf("\n\n%s Bin = \n\n", binary); >>> printf("%lu Dec\n", strtoul(binary, &other, 10)); >>> printf("%lX Hex\n", strtoul(binary, &other, 16)); >>> printf("%lo Oct\n", strtoul(binary, &other, 8)); >>> printf("\nPress ENTER to continue..."); >>> fpurge(stdin); >>> gets(hitkey); >>>} >>> >>> >>>**************************************************************** >>>* Michael Smith * Dartmouth, NS (Canada) * >>>* aa529 AT cfn DOT cs DOT dal DOT ca * Chebucto FreeNet (902)494-8006 * >>>**************************************************************** >>>* Words of Wisdom: * >>>* Beware of programmers carrying screwdrivers. * >>>* MACINTOSH: Machine Always Crashes If Not The OS Hangs * >>>**************************************************************** >>> >>> >>> -- Technische Universitaet Wien Institut fuer Werkstoffe der Elektrotechnik Dipl.-Ing. Paul FULMEK Tel. (+43 222) 58801/3955 FAX: (+43 222) 50 41 587 Gusshausstrasse 27-29 Austria - 1040 WIEN