| | |
Writing a magic numbers program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2009
Posts: 10
Reputation:
Solved Threads: 0
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..
what do you mean by magic numbers?
Example:
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.
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 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.
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()"
.
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.
> 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!
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!
![]() |
Similar Threads
- Program for Random numbers having a bit of trouble. (C++)
- Need help with ascending numbers program. (C++)
- How do I reverse numbers in my program (C++)
- Simple questions: short time (please help!) (C++)
- can anyone help me with writing a magic square program? (C)
- Tic Tac Toe Help (C++)
- writing a simple cat program (C)
Other Threads in the C++ Forum
- Previous Thread: STL list container and duplicates
- Next Thread: Re: SQL ado
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






