|
yup Plato.. what you said is correct ! there the array is infact a array of pointers to "struct s_Test " rather then a array of "struct s_Test ".
"Think big, think fast, think ahead. Ideas are no one's monopoly"
|
|
|
|
|
1) The source buffer for memcpy is too small. It is just 5 characters ("Paul"+zero), but you specify 30. This will result in a memory access error. A valid value for memcpy source len would be strlen("Paul")+1.
2) Declare the Test array as array and not as pointer array. So instead of struct s_Test* Test[10]; do a struct s_Test Test[10];
3) If you have done step 2 you don't need a dereferenced access to the name member variable any more. So the memcpy would look like:
memcpy(Test[0].name,"Paul",strlen("Paul")+1);
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
Thanks for all of those suggestions and help. I know I am being awkward but I really want to get it working using a pointer to the structure. I could do it the normal way no problem but I only want to allocate the memory as I need it. I don't want it to be a static array.
Is it not possible to have a pointer to a structure with instances aswell??
|
|
|
|
|
Sure, this is possible too:
struct s_Test
{
char name[30];
};
s_Test *Test;
void main()
{
Test = new s_Test[10];
memcpy(Test[0].name,"Paul",strlen("Paul")+1);
delete []Test;
Test = NULL;
return;
}
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
If you need a table, you need a table. How do you understand a pointer to a structure with instances as well ? To be able to point at something, you need that the something exist in the memory. It is therefor impossible to have a table without allocating some memory for it.
~RaGE();
|
|
|
|
|
Thanks, have it sorted and know the reason y it can't just do it like that.
thanks for all ur help.
grahamoj
|
|
|
|
|
What you really need is a vector or list of structures but this is a little too complicated to start off with. You can look up vector or list in the help for examples if you want. I assume that you will not know how many structures you will have at compile time and that is why you want a dynamic array. You can create a large array of pointers to your structure. This will take 4 bytes per element. Then allocate your structures when you need them. Have an integer keep track of the current number of structures. Try this:
struct s_Test
{
char name[30];
}
struct s_Test* Test[10];
int nTestCount = 0;
void main()
{
// Add a struct and initialize
Test[nTestCount] = new Test;
strcpy( Test[nTestCount]->name,"Paul");
nTestCount++;
// Add a struct and initialize
Test[nTestCount] = new Test;
strcpy( Test[nTestCount]->name,"John");
nTestCount++;
for(int i=0; i < nTestCount;i++) {
printf("%s\n",Test[i]->name);
}
return;
}
|
|
|
|
|
Hello,
Is an access to a variable with static modifier faster than a normal variable?
I have a recursive function:
void recursiveSolve(char *pszInput, int nItems)
{
int pArray[10];
} The initial contents of pArray doesn't matter, it gets overwritten in all cases. If I declare pArray as static int[], would the recursive function be faster? I don't know, perhaps a static variable has a fixed position in memory and doesn't get allocated again and again when the function calls itself recursively. Do you know?
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
I think so.
Because a saying said that the more space, the less time.
When stored as static varibles the more space is needed (the none-static varibles will be freed when they won't be needed), so I think the function needs less time to run.
Do you think I am right, don't you?
LeonOrient
|
|
|
|
|
I don't know if that saying applies to this problem
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
It shouldn't matter. It would be better to try and optimise using a better algorithm than changing to static variables
Using static variables is a C concept rather than a C++ concept.
It can be very problematic if you have to port the code into a DLL (look at the MSVC6 STL problems with DLL's for the perfect example)
|
|
|
|
|
i am sorry my friend... static variables is not only a concept in C but it is extensibly used in C++ too. infact "static var" concept is not confined to any language or OS. its a generic concept, which is used in many languages and operating systems. there are some solutions, which are best implemented with static concept.
"Think big, think fast, think ahead. Ideas are no one's monopoly"
|
|
|
|
|
BhaskarBora wrote:
static variables is not only a concept in C but it is extensibly used in C++
Perhaps I worded it badly. But being able to do it doesn't mean you should.
If you have to do something like this why are there so many discussion about the 'meyers singleton' pattern and order of destruction. Dynamic allocation of memory through a static pointer can be walking a dangerous road. Especially if you need to control the order of destruction.
|
|
|
|
|
dear friend ! its up to you how you perceive things !
"Think big, think fast, think ahead. Ideas are no one's monopoly"
|
|
|
|
|
hi there .. u r right partly...
all static variables (no matter where they are defined) are not created on stack like local vars. and also static vars are created once for a process/program and remain till the end. this is the reason when your function has static var array defined rather than a local var array, the execution is faster. as static var is created during the program startup and in your case not everytime when you invoke the function (recursive or otherwise). if it would have been a local array then execution would have been little slower as compare to the static array version (as OS will allocate the array on stack everytime you call the function and removes it from stack when function returns).
static var array is shared in all calls to the function. Also, there is a wastage of memory when you are not using the array. to over come this, you can define a 'int pointer' as static and allocate the memory when you need to use the array. when you no longer want the array, relase the allocated memory. this would be a smart solution !
"Think big, think fast, think ahead. Ideas are no one's monopoly"
|
|
|
|
|
Thanks! I will try the static pointer idea!
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
Now I have been assigned a task to do a FDD test. During the project I don't know how to make the Floppy-Disk-Device's LED blinking. Could you tell me some solutions to it, please.
Thank you!
LeonOrient
|
|
|
|
|
You cannot access the LED of a floppy disk through software!!! It is an integral part of the floppy disk and it has nothing to do with the operating system. Maybe, you could flash the HDD LED (since the BIOS does it) but not that of a floppy.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
Oh, Thanks.
Now I have another question, could you help me?
How can I carry out a Sequential-Verify test on floppy disk in VC?
Thank you very much!
LeonOrient
|
|
|
|
|
Sorry but I don't know.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
Now I have made FDD's LED blinking as my special ratio
the way is to access some special ports
in addion,
it requires to load a driver
|
|
|
|
|
Hi~
Below source is that find a file on ftp server. (from MSDN example)
By the way, no problem on windows iis ftp server
, but finder.FindFile() always return 1 on unix server .
What's wrong??
CInternetSession sess(_T("MyProgram/1.0"));
CFtpConnection* pConnect = NULL;
pConnect = sess.GetFtpConnection(_T("ftp.microsoft.com"));
CFtpFileFind finder(pConnect);
// start looping
BOOL bWorking = finder.FindFile(_T("*")); // bug !!
while (bWorking)
{
bWorking = finder.FindNextFile();
printf("%s\n", (LPCTSTR) finder.GetFileURL());
}
There are two men, one is a programmer, another is a man.
|
|
|
|
|
I got a ownerdrawn clistctrl that I have a bk image in.
How do I make the selected item background color about 50% transparent (I want to blend it with the bkimage)?
|
|
|
|
|
In the CListCtrl::DrawItem(LPDRAWITEMSTRUCT) function, you can manage the CDC object for fill each item to transparent.
I also need this implementation (with 100% transparent), and if you get please tell me how make it.
[]'s
Cris.
|
|
|
|
|
What the program actually does is that it searches an input file containing special characters contained in some words(i.e Ô , * and #352; ) .After finding such words it replaces those characters with this (i.e \o^ , \e^ and \sh respectively).I hope you will have the picture now.
SPECIFICATION
Deal with input or check whether input has the following special characters, i.e. read a file of text containing a list of words and check for the occurrence of these characters:
Ô or ô * as used in the word "pôô"
* or * - as used in the word "r*ma"
#352; or #353; - as used in the word "le#353;a#353;a"
If a word has any of these character replace each character by the
following characters respectively:
ô with \o^
* with \e^
#353; with \sh
I would appreciate it if you could could have a short program to sort
this issue out.
Let me say that it should be like this:
input -> words.doc
pôô r*ma le#353;a#353;a aôwô b*thô
output -> c:\output.txt
p\o^\o^ r\e^ma le\sh;a\sh;a a\o^w\o^ b\e^th\o^
Yes the text file is ASCII format(that "#352;" represent an S with a cap on top).It is Northern Sotho language(South African language)
|
|
|
|