|
Thank you both! I appreciate it. I will take a look at shFileOperation.
-Ian
|
|
|
|
|
Hai,
I'm new to programming...I have to calculate some values in a func and get those values outside the func..
ie i'm doing as below
main()
{
float *val1 = NULL;
float *val2 = NULL;
........
myfunc(&val1,&val2);
myfunc2(*val1,*val2);
.........
}
int myfunc(float *V1,float *V2)
{
int cal1 = 10;
.....
*V1 = cal1 / 2; ---> It does'nt give me any error,but when I debug it gives me access violation in memory 0x0000000 here...
*V2 = cal1 / 5;
return 0;
}
where am I going wrong...
Thanks a lot..
|
|
|
|
|
myfunc(&val1,&val2); means you are passing the address of val1. Val1 is a pointer. Try
myfunc(val1, val2);
Also you need to initialize val1 and val2 to point to something. I hope you did that in the .....part of your main.
|
|
|
|
|
No I did'nt initialize anything..
My basic idea is this..I have to compute the values of two float variables in myfunc1 and use those values in myfunc2.How should I do this..
Thanks a lot
|
|
|
|
|
int main()
{
float v1 = 0.0;
float v2 = 0.0;
....
MyFunc(v1,v2);
...
return 0;
}
void MyFunc(float& v1, float& v2)
{
//Change value of v1 & v2
}
"float&" versus just "float" means that you will be passing by reference, not by value. I suggest you look up by value and by reference in your text/reference book to get a better understanding of this concept.
|
|
|
|
|
1. You can use references.
float val1, val2;
myfunc1(val1,val2);
myfunc2(val1,val2);
...
void myfunc1(float & val1, float & val2)
{
val1 = 10/4; etc etc
}
myfunc2 stays the same.
2. If you want to use pointers
float val1, val2;
myfunc1(&val1, &val2);
myfun2(val1,val2);
your functions should remain the same.
|
|
|
|
|
ok first off when passing a pointer as an argument like you have you dont need to do & or * just use the variable name as long as the types match. you also need to either assign your variable something other than NULL either assign another pointer to it or do a new or malloc wicherver you prefer to create your variable, dont forget to delete your variable when your done.
btw that error your getting is that value becuase thats the same value as the pointer your passing
NULL = 0x0000000
<br />
int main()<br />
{<br />
float *var = new float;<br />
float *var1 = new float;<br />
<br />
myfunc(var, var1);<br />
<br />
printf("%f, %f", var, var1);<br />
delete var;<br />
delete var1;<br />
}<br />
<br />
void myfunc(float *var, float *var1)<br />
{<br />
}
|
|
|
|
|
main()
{
float val1 = 0.0;
float val2 = 0.0;
........
myfunc(&val1, &val2);
}
You need to allocate some memory for Val1 and Val2. What you did allocated memory for 2 variables that were capable of storing the memory address of Val1 and Val2, but not the values themselves.
For instance:
int i; //declares that i is an int and allocates memory
int *j; // declares that j can store a memory address to a location in memory that can store an
//integer - but note, no memory has been allocated for that integer here
j= &i; //assign j (capable of storing an address) the address of i (which in turn can store an int)
Hope this helps you....
|
|
|
|
|
The other guys are right. I just want to add some comments.
Pointers are hard for novices. They seperate the experts from the novices!
Don't just fix the code, spend some time to understand what is wrong. User pencil and paper if you must, and trace out exactly what is going on.
It will be helpful to lookup handles as well. What you have done is created a handle (which is a topic even more advanced than pointers), so you will want to see what you have done.
|
|
|
|
|
does anyone know of any good C++/MFC tests that I can download to check my proficiency, or list of interview questions? I've been reading "The Art of Computer Programming" by Donald Knuth and was never more aware of what I don't know until now.
Thanks in advance!
[A brave person isn't always necessarily a smart person]
bdiamond
|
|
|
|
|
bdiamond wrote:
does anyone know of any good C++/MFC tests that I can download to check my proficiency...
Try www.brainbench.com[^].
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
thanks. I was looking for something free, though. I'm not going to be able to pay the 49.95 right now.
[A brave person isn't always necessarily a smart person]
bdiamond
|
|
|
|
|
Sorry. When I last took one of their exams (July-ish), it was free.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
not a problem; thanks for your never-ending help anyway!
[A brave person isn't always necessarily a smart person]
bdiamond
|
|
|
|
|
I always like the real world tests. Head over to sourceforge.net (there are plenty of other places too, this one just happens to be popular), find a C project with some bugs, fix one, and see if your patch is accepted. Some projects will accept anything, but others are very picky, if you can find a picky one and get complex patches accepted then you know you are a good programer.
Tests generally are too short to see how programers will do in the real world.
If you really think you are good openbsd is about the hardest project to get things accepted to. www.openbsd.org. Beware, the people there are hard to work with on a personal level, in addition to being picky about the code they accept.
|
|
|
|
|
No, I'm probably not that good (for www.openbsd.org), but thanks! I will look into the SourceForge.Net thing, though. I've been there before, but I didn't know there were opportunities to make modifications to code like that and see if they would be accepted. Thanks again.
A brave person isn't always necessarily a smart person
bdiamond
|
|
|
|
|
i need to know how run my program in system boot
without using divices driver?
faroq from yemen thammar
working in thammar universty and my intersted about network and security
im programmer from 6 years ago and ihave my B.C from this universty
|
|
|
|
|
Add it to the Startup folder, or the Run key in the registry.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
My VC++ 6.0 SP 5 started misbehaving so I deleted it and reloaded the entire Visual Studio plus SP 6.
I am getting assertion (olelink) with what appears a goofy file path.
I have never debugged this part of MFC and have no clue what path should be there. However, I have installed Visual Studio many times before and never had this problem of missing OLE stuff.
I noticed that some DCOM stuff does not get installed due to different security requirements in WIN2000 SP4.
I am contemplating reistalling Win2000 back to SP 1 and than installing Visual studio again. ( Because MS fix for this security problem did not work for me few months before)
It worked before but would prefer less painfull and time consuming way to resolve this OLE problem if possible.
Any help is greatly appreciated.
Vaclav
|
|
|
|
|
Is there a way to authorize with WinInet in the same way as using the CredentialCache.DefaultCredentials in .Net?
Using WebClient and the DefaultCredentials is very nice in .Net, but I'd like to do the same thing in plain old C++ and Win32/WinInet.
Cheers
|
|
|
|
|
In my current undertaking project, i am developing a window dialog based application as player console to control a piece of hardware for tv reception. can anyone suggest me in VC++, how can i control volumn and make the player screen to full screen?
thx in advance
|
|
|
|
|
There are some good articles on this website about DirectX programming.
|
|
|
|
|
May anyone suggest me how to use Progress Bar Control to show
1) the pecentage, say, how 80 is weighted in the range from 60-100?
2) the completion of a function execution?
thx in advance...
|
|
|
|
|
jooo wrote:
1) the pecentage, say, how 80 is weighted in the range from 60-100?
Use:
m_ctrl.SetRange(60, 100);
m_ctrl.SetPos(80); Now the progress control will show 50%.
jooo wrote:
2) the completion of a function execution?
If you are executing just one function, the progress control will show either 0 or 100%. Not real useful in that situation. It would be useful if you had something to the effect of:
m_ctrl.SetRange(0, 100);
Foo1();
m_ctrl.SetPos(33);
Foo2();
m_ctrl.SetPos(66);
Foo3();
m_ctrl.SetPos(100);
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
yup, i got it, thx very much...
btw, i noticed that SetPos(int nPos), is there any alternative to accept double as parameter like SetPos(double nPos)?
|
|
|
|