Writing a magic numbers program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2009
Posts: 10
Reputation: patria987 is an unknown quantity at this point 
Solved Threads: 0
patria987 patria987 is offline Offline
Newbie Poster

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

 
0
  #1
Jun 1st, 2009
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..
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,597
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1489
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Writing a magic numbers program

 
0
  #2
Jun 1st, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,669
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 123
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: Writing a magic numbers program

 
0
  #3
Jun 1st, 2009
i think he means

  1. unsigned long MAGIC_NUM = 0xDEADBEEF;
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,597
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1489
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Writing a magic numbers program

 
0
  #4
Jun 1st, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,669
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 123
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: Writing a magic numbers program

 
0
  #5
Jun 1st, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Writing a magic numbers program

 
0
  #6
Jun 1st, 2009
> 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!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC