what do you mean by magic numbers?
Example: int i = 123; the "123" is considered a magic number. Is that what you mean?
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
i think he means
unsigned long MAGIC_NUM = 0xDEADBEEF;
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
Isn't that the same thing I posted? That is, they are both magic numbers.
I think one way to write a program to find them is to read each line of the file and search it for a digit (0-9). If a digit is found, then most likely it will be the beginning of a magic number.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
i was joking. what the heck is a "magic number" anyhow?
i understand magic numbers as being arbitrarily defined constants that, when they are poorly documented, are indicative of poor coding practice.
EDIT -- oh, wait, you mean for a file type. one or more numbers at the very beginning of a file.
well, i guess you need to read the very first line of text, then convert ascii to integer, and perform a basic comparison on the first several bytes of the same length as the number being searched?
um, yeah, okay i get it now. i didn't understand how basic this question was. :$
use " fgets() " and " strtol() " or " atol() "
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
> Can anyone help me write the program to find the magic numbers in c/c++??
Sure, but you need to decide whether it's C OR C++ (not a random mix of both), and you need to put in some actual effort yourself.
There are some unfounded rumours that there are some threads which noobs are supposed to read, which probably explains why you haven't read them :icon_rolleyes:
> I have looking for this solution for a long time
So you've already failed to google your way to a free lunch....
> so ill be grateful if sumone here can solve it..
So now you want us to do your homework.
"TING" - next customer please!
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953