943,601 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3565
  • C++ RSS
Jun 1st, 2009
0

Re: C / C++ FAQ's and Practice problems

Expand Post »
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..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
patria987 is offline Offline
9 posts
since May 2009
Jun 1st, 2009
0

Re: Writing a magic numbers program

what do you mean by magic numbers?

Example: int i = 123; the "123" is considered a magic number. Is that what you mean?
Last edited by Ancient Dragon; Jun 1st, 2009 at 1:56 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jun 1st, 2009
0

Re: Writing a magic numbers program

i think he means

  1. unsigned long MAGIC_NUM = 0xDEADBEEF;
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Jun 1st, 2009
0

Re: Writing a magic numbers program

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.
Last edited by Ancient Dragon; Jun 1st, 2009 at 2:41 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jun 1st, 2009
0

Re: Writing a magic numbers program

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


.
Last edited by jephthah; Jun 1st, 2009 at 11:46 am.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Jun 1st, 2009
0

Re: Writing a magic numbers program

> 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

> 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!
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: STL list container and duplicates
Next Thread in C++ Forum Timeline: Re: SQL ado





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC