Can anyone help me write the program to find the magic numbers in c/c++??I have looking for this solution for a long time so ill be grateful if sumone here can solve it..

## Recommended Answers

what do you mean by magic numbers?

Example: int i = 123; the "123" is considered a magic number. Is that what you mean?

i think he means

unsigned long MAGIC_NUM = 0xDEADBEEF;

## All 5 Replies

what do you mean by magic numbers?

Example: int i = 123; the "123" is considered a magic number. Is that what you mean?

i think he means

unsigned long MAGIC_NUM = 0xDEADBEEF;

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.

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()"

.

> 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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.