|
Any one knows how to convert a binary array to a decimal array in C++? Thanks.
mIchAel Liu
__________________________________________________________
The secret of business is to know something that nobody else knows.
|
|
|
|
|
what's a "binary array" ?
-c
All you have to do is tell the people they are being attacked, and denounce the opposition for lack of patriotism and exposing the country to danger.
-- Herman Goering, on how to control the public
|
|
|
|
|
... and what's a "decimal array" ?
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
1111 0000 1111 1000 = F0F0
is "111100001111000" a string?
Developing with C++ is like programming by the seat of your pants
|
|
|
|
|
Actually, I have a big integer value, larger than 80 bits which I can't use DOUBLE to hold this value and print it out. Now I have a array to hold this value by binary integers(0,1), then I need to convert it to another array which hold decimal integers(0 to 9) to present this large value. Because I can't use power of 2 ( if I have 256 bits, then I can't hold the it), I have touble to convert it.
mIchAel Liu
__________________________________________________________
The secret of business is to know something that nobody else knows.
|
|
|
|
|
CString * pArray;
int iArraySize = 4;
for (int i =0; i< iArraySize; i++)
{
pArray[i] = "abc";
}
It chokes at the line where I assign it "abc" . Previously I had assigned it 2*i, so I thought that since i is int and p String, thats causing the crash. But the above is not happy.
Whats wrong?
Appreciate your help,
ns
|
|
|
|
|
Why don't you assign the array like that:
const int iArraySize = 4;
CString Array[iArraySize];
for (int i=0; i < iArraySize; i++)
{
Array[i] = "abc";
}
<pre>
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Fine. Thanks for that!
How will I pass this array into a function?
myFunc( CString * pArray)
called as
myFunc(pArray)
? ????
Appreciate your help,
ns
|
|
|
|
|
eh... If I get you right you could call it as myFunc(&pArray), I think
|
|
|
|
|
try this:
void Arr(CString pArray[], int intArrCount)
{
for(int i=0; i<intArrCount; i++)
pArray[i] = "abc";
}
you simply pass the array like that:
CString array[4];
Arr(array, 4);
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Exactly the info I needed. Many many thanks!
Appreciate your help,
ns
|
|
|
|
|
I hope you are not writing software I will install for any reason on my computer in the future.
I am not bashing you, I am just figuring out you don't know what a pointer is. And it worries me.
sometimes it helps to look at the IL generated code
a MS guy on develop.com "answering" .NET issues
|
|
|
|
|
Well,
I am just trying to pattern it after a char array which we pass in by name as
myFunc(myArray)
where its
myFunc(char * myArray)
(Am I wrong about this too? )
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
I am just trying to pattern it after a char array
Actually, you're better off using the MFC collection class CStringArray which seems ideally suited for your purpose, since you don't have to worry about freeing up storage, knowing its length, etc. Here's what I mean:
CStringArray arrayOfStrings;
for (long nIndex=0; (nIndex < 4); nIndex++) {
arrayOfStrings.Add ("abc");
}
myFunction (arrayOfStrings);
...
void myFunction
(CStringArray& stringArray)
{
}
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Then why don't you help the guy find out what a pointer is, instead of just telling him that he can't program?
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
I think there are a couple fundamental concepts you're missing here, so I'll try to explain it... hopefully this makes sense.
In a nutshell, your assignment of pArray[i] = "abc" fails because pArray isn't pointing at anything useful in your sample code. Your first line creates the pointer, but at that point it's merely a pointer to a CString; it's not really a CString yet.
A CString is an object, which is very different from the char data type. What's the difference between a CString pointer and a char pointer? You can do this with a char pointer:
char *c;
c = "abc";
When the compiler sees a literal string like "abc", it actually creates that string as a globally-accessible char array variable, which can then be "pointed at". This happens automatically for you, and you're not even really aware that it's happening. The char pointer in the above example can then point at that global variable because the datatypes match. It's a character array located at some address in memory, and you've got a character pointer that can store that address. Essentially, the above code is equivalent to doing this:
char cArray[4];
char *c;
cArray[0] = 'a';
cArray[1] = 'b';
cArray[2] = 'c';
cArray[3] = 0;
c = cArray;
Obviously this is a pain in the ass to code, so conveniently C and C++ compilers handle character strings automatically for you.
Okay, so now where does your CString come in? A CString is a C++ class that wraps character arrays; by itself it's not actually an array of characters. It's not a primitive datatype like char or int. If you tried the following, you'd get a compiler error:
CString *p;
p = "abc";
In this case, p is supposed to be pointing to a CString. "abc" as you learned is actually an array of characters, exactly 4 bytes long. You can't convert from an array of characters to a CString pointer; they're incompatible. You need to point at an actual CString object.
Knowing that, why does your code compile? Your code compiles fine because you access the pArray pointer through the reference operator []. This special operator lets you treat the pointer as a sort of index into an array. You can move anywhere within the array by just changing the index. However, there's a problem in your example. Your pArray isn't pointing at anything. You never initialized pArray to point to an array of CString objects. pArray is pointing at some garbage value off in no-man's land in memory. pArray[i] is trying to move around in that range, and it throws an access violation.
So, the bottom line is you need to initialize your pArray variable to actually point at some valid location in memory. You can follow some of the other examples, or even do something like this:
int iArraySize = 4;
CString *pArray = new CString[iArraySize];
for( int i = 0; i < iArraySize; i++ )
{
pArray[i] = "abc";
}
delete []pArray;
In this case, pArray points to an array of CString objects, dynamically allocated on the heap. The pointer can access each of the four through the reference operator.
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
Many thanks. That really cleared up things for me.
Appreciate your help,
ns
|
|
|
|
|
I'm worried, this is commercial s/w you're developing?
Developing with C++ is like programming by the seat of your pants
|
|
|
|
|
How do you make a number (integer) into a CString?
Appreciate your help,
ns
|
|
|
|
|
CString str;
str.Format("%i", iFoo);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you. Any thoughts on my CString * pArray thread? Its quite short and probably obvious to you...
Appreciate your help,
ns
|
|
|
|
|
I wish to make a SDI CFrameWnd based app appear like a dialog based app. Yea, I know I can create a dialog based app but for reasons I won't go into here, I don't want to go that route.
I used Spy++ to look at the style and dwStyleEx bits a a CFrameWnd and a dialog based app, and I've overloaded CMainFrame::PreCreateWindow() and have fiddled with the style and dwStyleEx bits, but I've had no luck.
TIA,
JB
|
|
|
|
|
Anyone have any experience building an app that uses MFC Doc/View and has a look and feel similar to VC6 ? I am trying to modify some code that is based on Doc View. Currently the code has a primary document, which is basically a project, that holds classes, and diagrams. When you open a file or create a new project this is waht you create first. Then if you add a diagram, you can edit the diagram as a new document type. All of which leads to a lot of clutter of MDI windows.
What I would like is to modify it so that when you open a project the main view is housed not in a MDI frame, but in a toolbar like in VC6 (the "Workspace" toolbar). Then any diagrams opened can open up in an MDI frame. Further more, each new project opened up, would add itself to a list that you toggle back and forth between projects.
Is this feasible in DocView ? The reason I want to do this is because the original code is written in DocView and I wanted to reuse(not break) as much as possible.
Any suggestions would be greatly appreciated !
|
|
|
|
|
If I understand what you want correctly, you might want to check out Cristi Posea's docking bars (nw). I've used them in a program to put a tree control that is actually a CView of the document beside the main view. The tree lists items in the project and allows you to select items into the main view.
people are not very wise / don't know their limitations /
don't know what death means / when they play their dirty games 'Killing Fields' Funker Vogt
|
|
|
|
|
Hi. I have been asked to develop my first telephony application. I think I want to do it with Visual C++ or Visual Basic.NET. The application: A program that will let the user dial in to his/her voice mail and access all of the features of the voice mail throught the computer. Does anyone know of existing libraries that might be helpful? Do we need a special modem? Does anyone know if it might be easier to implement in another language?
|
|
|
|