|
Do you have STL available? If so just use vector or map.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
How can he have STL access in C ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Assuming you're using C, and not C++, you need a JobCode*, and you need to use malloc and free, which means you'll be in trouble if you want to grow your array without losing it. You'd need to memcpy the old one into the new space.
Of course, if it's C++, then you need what you should always use, even in ATL/MFC - the STL.
The other solution is to write your own linked list, but I'm not sure how totally ugly that would be, given that it cannot be in a class.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
Assuming you're using C, and not C++, you need a JobCode*, and you need to use malloc and free, which means you'll be in trouble if you want to grow your array without losing it.
How about realloc or is that not available in C?
|
|
|
|
|
Jack Squirrel Jr. wrote:
How about realloc or is that not available in C?
This is the epitome of a bad function. realloc() has been dubbed the one-function memory manager. If the new size of the block is smaller than the old size, realloc() releases the unwanted memory at the tail end of the block. If the new size is larger than the old size, the expanded block may be allocated at a new address and the contents of the original block copied to the new location. A pointer to the expanded block is returned, and the extended part of the block is left uninitialized. If you attempt to expand a block and realloc() cannot satisfy the request, NULL is returned. If pv is NULL , then realloc() behaves as though you called malloc() and returns a pointer to a newly allocated block, or NULL . If the new size is 0 and pv is not NULL , then realloc() behaves as though you called free(pv) and NULL is returned. If pv is NULL and size is 0, the result is undefined. In summary, realloc() is a prime example of implementation overkill!
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hello,
As Christian mentioned, you can write your own linked list. Basically you can write a set of functions for traversing your set of structures. A basic idea of this:
struct JobCodeNode
{
JobCodeNode* pNext;
JobCodeNode* pPrev;
JobCode* pNode;
};
struct LinkedList
{
void* pStartNode;
void* pCurrentNode;
};
LinkedList InitLList(void* pStart)
{
LinkedList LList;
LList->pStartNode = pStart;
LList->pCurrentNode = pStart;
((int*)pStart) = NULL;
((int*)(pStart + 4)) = NULL;
return LList;
}
This is just a basic idea and it can be extended beyond peoples imagination...
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Jeez does that bring back memories from 1993! I was hoping that I was forgetting something, but now I distinctly remember writing this code everyplace I worked from 84-93 (before I discovered mfc and collections). Thanks Bob
|
|
|
|
|
You forgot!
Back when I used to write strictly C code, I would create a general purpose
modeule to hadle things like this.
#define LISTHANDLE (void*);
LISTHANDLE List_Create(size_t record_size);
size_t List_Size(LISTHANDLE hList);
int List_Append(LISTHANDLE hList, void* pRecord);
int List_ReadNext(LISTHANDLE hList, void* pRecord);
int List_Insert(LISTHANDLE hList, void* pRecord);
int List_Sort(int (*callback)(void*,void*));
#ifndef BYTE
#define BYTE unsigned char
#endif
typedef struct st_NodeHeader
{
struct st_NodeHeader* pNext;
} NODE_HEADER;
typedef struct st_Header
{
size_t nRecSize;
NODE_HEADER* pHead;
NODE_HEADER* pTail;
NODE_HEADER* pCurrent;
} HEADER;
LISTHANDLE List_Create(size_t record_size)
{
HEADER* pHeader = (HEADER*)malloc(sizeof(HEADER));
if( pHeader )
{
memset(pHeader,0,sizeof(HEADER);
pHeader->nRecSize = record_size;
}
return(pHeader);
};
int List_Insert(LISTHANDLE hList, void* pRecord)
{
if( hList && pRecord )
{
HEADER* pHeader = (HEADER*)hList;
size_t nNodeSize = sizeof(NODE_HEADER) + pHeader->nRecSize;
NODE_HEADER* pNode = (NODE_HEADER*)malloc(nNodeSize);
if( pNode )
{
BYTE* pRec = ((BYTE*)pNode) + sizeof(NODE_HEADER);
pNode->pNext = (NODE_HEADER*)0;
memcpy(pRec,pRecord,pHeader->nRecSize);
return(1);
}
}
return(0);
}
int List_ReadNext(LISTHANDLE hList, void* pRecord)
{
if( hList && pRecord )
{
HEADER* pHeader = (HEADER*)hList;
if( pHeader->pCurrent )
{
BYTE* pRec = ((BYTE*)pNode) + sizeof(NODE_HEADER);
memcpy(pRecord,pRec,pHeader->nRecSize);
pHeader->pCurrent = pHeader->pCurrent->pNext;
return(1);
}
}
return(0);
}
Well you get the idea. Once it is written, you don't have to worry about how
it works anymore. You can expand it to include file I/O for saving to disk,
and you can change how it works interanly, without having to modify the code
that uses it.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
This brings back memories of years of writing OS/2 C code. I definitely never thought I'd be doing this coding again. Thanks John!
|
|
|
|
|
You're welcome
Tom Archer wrote:
Jeez does that bring back memories from 1993!
I had to write such a module in a class 2 years ago and we were forced to do it without any other libraries. My memories might not go back to 1993, but I sure am glad that they are memories.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
My application uses a tray icon (Shell_NotifyIcon) and I need to access the data of my icon displayed.
Does anyone know what a HICON points to and how to manipulate the icon data, or simply after loading an icon yourself, using that in the tasktray or converting it to a HANDLE windows can use?
thanks
|
|
|
|
|
c. s. wrote:
I need to access the data of my icon displayed
What data is this ?
an HICON is a simple handle on your icon, a sort of identifier given by windows which you get after calling one of the multiple CreateIcon...() functions. This handle can then be passed as a parameter for functions such as DrawIcon to actually draw your icon somewhere in your device context.
Search code project (Using the search utility above) with :
tray icon
and you will get a lot of example about how to handle tray icons.
~RaGE();
|
|
|
|
|
thanks, but that isn't my problem. It will probably helpful if I explain what I want to do. I have an animated icon 12 frames long, I also want it to change color depending on what the application is doing, however I don't want to end up making 76 different icons.
I need to access the pixel data so I can overlay a color with 3dnow and mmx, so I need access to the actual memory or load the icon myself and if possible, set the data up the same way the data is set up that a HANDLE points to, and point my HICON at it.
|
|
|
|
|
i want an algorithm for computing the vector that coming out from the rotation of another a vector given that we have the angle of rotation
please coz i eed it in a project in c++
|
|
|
|
|
Sounds like a simple trig problem to me. Sounds like homework, too.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
You don't seem to learn that when you don't ask specific questions about problems in your code, that almost nobody is willing to help you... A good start would be to just grab your textbook and try to implement to algorithm destcribed there.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
NOOO
DONT MISSUNDERSTAND ME!!!!!
i dont want anyone to write the code for me i want only the law of computing this
THE LAWWWWWWWW
ONLY THAT!!!!
thats what i mean by an algorithm i dont mean the code please dont misunderstand me
thats a question about mathematics
how can i rotate a vector with a given angle of rotation?????????????
|
|
|
|
|
So it's only the theory that you are after? In one of your posts you said that you went through google, yahoo and more to find a solution. If that's true, I wonder why you didn't find this[^]. The answer was on the first page of a google search with the keywords: rotate 3d vector.
You'll find only theory there, but you can implement it very easy. I know it's true, since I already programmed the solution in Java.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
yes i found that but i want to know if the rotation id for only 3d vectors
i mean that this page on google is every thing about rotation
i am sorry i may dont ask specific questions but thats because of my poor english
|
|
|
|
|
I don't know what that's not good, since it is exactly the theory about rotating objects, especially 3D vectors... Believe me, I know it, since I implemented that exact algorithm in Java during one of my classes...
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
If you rotate (x,y) by angle r to get (x',y') then
x' = cos(r)*x - sin(r)*y
I'll leave the formula for y' as an exercise.
You can at least do some of your homework yourself
Steve T
|
|
|
|
|
Mr. steve thats not a homework the home work is to do it in c++
so i need to know the law first
thats all
but i want ask some thing this thats for rotation of vector of two dimensions only so if there are also rotation of the vector of n size??????
|
|
|
|
|
This seem very ridiculous to me
If the teacher is only interested in your abilitly
to write the solution in C++ then ask your teacher
for the required formulas.
And if you want to tell us this is not a C++
question then why are you asking in a C++ forum?
You can use Google to find this sort of solution,
and you will learn more by doing so than you will
by having someone spoon-feed you the answers.
Steve T
|
|
|
|
|
no my teacher wont refuse if i asked him for the law but there is a long way between us i have to travel to go him because he is not here now he is travelling abroad & will come to the collegue the next saturday when we will give him the solution on disks
& i asked here in c++ forums bacause i thoght u could help me nothhing more coz u may have the answers & will save time for me
i logged onto many websites like ggogle & yahoo & others but i couldnt found my need so i asked here
and i dont want u to thought badly of me i just a beginner need help in c++ so could u help me in becoming one great programmer in such language coz i realy want to be one like this
i dont want to be a lazy person who needs to be fed the answers with spoon like u said nooooooo absolutely not
if i was like i would have given the whole proplem to any programmer in my country and give him money for programming that for me without any effort
i wouldnt have logged onto ur site to ask u for help
so all i want in this forums is HELP!!
OK have u understood me now
i hope u changed ur mind about me
|
|
|
|