Posted: Mon May 19, 2003 3:57 pm
Notice I just edited my post above...
postcount++;
postcount++;
Craig P. wrote:liquidsquid wrote:void main(void)
Non-standard, diagnostic required. Microsoft violates the standard by accepting this without a diagnostic.
I don't know if the C standard allows it, but the C++ standard allows no return from main(), e.g.Code: Select allint main(void)
{
// ... etc ... - no return statement
}
Of course, VC6 (haven't tried VC7.1 yet) converts this into void main().
muyuubyou wrote:Of course it's stored in binary . The scanf function does all the conversion (in the same way it does when you pass it a dec number via %d).
In fact, when you explained your problem I thought you wanted to program the conversion yourself, and not simply calling scanf to do it
How is your progress going? I want you to start with some SDL and OpenGL real soon.
So WTF is the difference between a reference and a pointer? From what I unserstand, a reference is a variable or constant which refers to another object or variable, thus it contains an address. So does a pointer. You have to forgive me because I haven't delved into C++ in a LONG time, but apart from semantics and the way you write code, the generated assembly is essentially the same between the two.
For example, the hex number a2d3 (my test value) comes out as 41683... I wouldn't be able (ATM anyways) to string together the four hex values into a sensible binary
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
long Convert(char *s)
{
long result = 0;
for ( ; *s != '\0'; s++) /* examine string 1 char at a time */
{
if (*s >= '0' && *s <= '9')
result = (result << 4) + (*s - '0'); /* handle digits */
else if (*s >= 'A' && *s <= 'F')
result = (result << 4) + (*s - 'A') + 10; /* handle A-F */
else if (*s >= 'a' && *s <= 'f')
result = (result << 4) + (*s - 'a') + 10; /* handle a-f */
else
break; /* no more hex digits */
}
return result;
}
int main(void)
{
char buffer[12];
long value;
do
{
printf("Enter hexadecimal number...\n");
fgets(buffer, sizeof(buffer), stdin); /* read string */
} while (!isxdigit(buffer[0])); /* until we get valid hex */
value = Convert(buffer); /* convert from hex */
printf("0x%08lX hex is %ld dec\n", value, value); /* output */
printf("Hit Enter to quit: ");
fgets(buffer, sizeof(buffer), stdin); /* wait for user to hit Enter */
printf("Have a nice day\n");
return 0; /* Tell the OS there was no problem */
}
it is not programming on the PC, though I know many of you are sticlers for standards, sometimes you just have to say "NO" and go the efficient way
just brew it! wrote:For example, the hex number a2d3 (my test value) comes out as 41683... I wouldn't be able (ATM anyways) to string together the four hex values into a sensible binary
It's not that hard. Here's an example of how to do the conversion yourself:Code: Select all#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
long Convert(char *s)
{
long result = 0;
for ( ; *s != '\0'; s++) /* examine string 1 char at a time */
{
if (*s >= '0' && *s <= '9')
result = (result << 4) + (*s - '0'); /* handle digits */
else if (*s >= 'A' && *s <= 'F')
result = (result << 4) + (*s - 'A') + 10; /* handle A-F */
else if (*s >= 'a' && *s <= 'f')
result = (result << 4) + (*s - 'a') + 10; /* handle a-f */
else
break; /* no more hex digits */
}
return result;
}
int main(void)
{
char buffer[12];
long value;
do
{
printf("Enter hexadecimal number...\n");
fgets(buffer, sizeof(buffer), stdin); /* read string */
} while (!isxdigit(buffer[0])); /* until we get valid hex */
value = Convert(buffer); /* convert from hex */
printf("0x%08lX hex is %ld dec\n", value, value); /* output */
printf("Hit Enter to quit: ");
fgets(buffer, sizeof(buffer), stdin); /* wait for user to hit Enter */
printf("Have a nice day\n");
return 0; /* Tell the OS there was no problem */
}