|
kir_MFC wrote: but if i debug the application
You mean running in debug mode or just stepping through every line? Are you sure you are running the same version (debug/release) on both the occasions?
|
|
|
|
|
With out knowing what error is happening, how one can help you?
Please tell more details about the error message.
- ns ami -
|
|
|
|
|
kir_MFC wrote: ...it is giving some error messages.
Is this supposed to be helpful?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hello Everyone there,
I am working on vc++6. An win32 console based application. I have this problem in my project...
Whenever I run my application the control comes to the function strcpy and stops and one dialog box appear by title "find source " and asking..."please enter the path for STRCAT.ASM." and a list of directories...
The strange behavior is that when I run the same code in a different win32 project, it runs perfectly....May be some setting...could u please help me out
code is....
char currentTime[20];
struct tm * pLocalTime;
strcpy(currentTime, ""); //error comes here
long int nLocalTime = 0;
time(&nLocalTime);
pLocalTime = localtime(&nLocalTime);
sprintf(currentTime,
"%04d-%02d-%02d-%02d.%02d.%02d",
(pLocalTime->tm_year) + 1900,
pLocalTime->tm_mon + 1,
pLocalTime->tm_mday,
pLocalTime->tm_hour,
pLocalTime->tm_min,
pLocalTime->tm_sec);
Thanks in advance,
Himangshu
I am a learner Always
|
|
|
|
|
Are you trying to debug? Got breakpoint in that line? What command are you using to run the exe from the IDE?
|
|
|
|
|
thanks smith...
I got that problem out....Donno I was using a char pointer before...Now I changed it to array...strange but its working now....
I was debugging it by pressing f5 and by putting a break point
Thanks anyway
I am a learner Always
|
|
|
|
|
I have a task where I am supposed to display the data(Clientname, id , year, license) on a list control from an XML file however when a new data is appended to the XML file with the same Clientname. I want the latest (i.e. recently appended data)should display.
Please let me know which function is required to perform this???
Thanks in advance.
modified on Wednesday, February 4, 2009 3:00 AM
|
|
|
|
|
- Detecting a change to a file - you want to use directory change notifications[^].
- Displaying the last item in a list in an XML file? Kind of depends on the schema of the XML file, but you could use XPath to find the last item, or iterate through the file - there are a lot of techniques - I'd advise you to work out how to use the XML library you're using to do this.
|
|
|
|
|
//Works
<br />
int py[5] = {0,1,2,3,4};<br />
int* pyp = (int*)py;
printf("%d",pyp[2]);<br />
<br />
//Doesn't.
<br />
show "2Dpointer\n";<br />
int py2[2][2] = {0,1,2,3};<br />
int **pyp2 = (int**)py2;<br />
<br />
printf("py2:%d",py2);<br />
printf("pyp2:%d",pyp2);<br />
<br />
printf("**pyp2[0][0]",pyp2[0][0]);
printf("**pyp2%d",**pyp2);
<code><br />
<br />
why? <br />
<br />
<div class="ForumSig">:beer:</div>
|
|
|
|
|
All index [] notation is converted to pointer arithmetic.
So, you declare
int py2[2][2];
the compiler knows the total size (2*2 = 4) and how wide each row is (2).
So if you do
py2[1][0]
the compiler can convert to
py2 + (1*2) + 0
But then you do
int **pyp2 = py2;
Now you have created an alias and lost all information about the dimensions of the array.
So, when you try to do
pyp2[0][0]
the compiler can only get to
pyp2 + (0*?) + 0
it doesn't know what to fill in for ?
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
but why does it work here ?
<br />
int py[5] = {0,1,2,3,4};<br />
int* pyp = (int*)py;
printf("%d",pyp[2]);<br />
As it shows, the memory has been laid out for these values,
[START_ADDRESS]4bytes,4bytes,4bytes,4bytes,4bytes.
So when you assign the pointer, it starts to point to the first item. Further when you make a pyp++ or pyp[], it's landing up on the right element. Here too, I'm not passing it any information about the size of the array. It's just the pointer and it's taking it up.
2D arrays, it's not too different from 1D. The next batch of numbers would be following.. err.. err. Okay as I'm typing this I'm getting it ..I'm not giving it any clue where the first row ends.. well..is that what you mean? sounds convincing but why not it work atleast for the first item? I'm just saying **pyp2. Just trying to get the value of the element it's currently pointing to. Why even this doesn't work?
btw, why the complier is not warning me about a meaningless assignment?
|
|
|
|
|
py2 is an address.
The contents of py2 are 0, 1, 2, 3.
Agreed ?
pyp2 is a pointer to a pointer.
pyp2 is initialized with the address of py2.
Now when you say *pyp2 it is taking the first value of 0 which it thinks is another address.
So, **pyp2 is trying to read the value at address 0. // Crash
If the contents of py2 were 5, 6, 7, 8,
**pyp2 will be trying to read the value at address 5. // Still Crash.
«_Superman_»
|
|
|
|
|
So, **pyp2 is trying to read the value at address 0. // Crash
Why should it crash?
*pyp2 = first row.
**pyp2 = first element of the first row.
What's wrong with it?
|
|
|
|
|
Smith# wrote: *pyp2 = first row.
**pyp2 = first element of the first row.
Wrong. I have tried to explain it in my previous post.
«_Superman_»
|
|
|
|
|
Now when you say *pyp2 it is taking the first value of 0 which it thinks is another address.
Yes. that's the address of the first pointer. I called it as 1st row. With **pyp2, I try to access the first element. in other words, *pyp2[0].
I agree that you cannot ask it go to the next pointer since it doen't know where first one ends. But what's the problem to access the "first-most" element? We have the address, what's the problem with taking it's address? Am I still missing something?
|
|
|
|
|
To access the first element you simply do *pyp2. Try it.
«_Superman_»
|
|
|
|
|
That will give me the address of the first element. Not the value.
|
|
|
|
|
It is giving me the value.
Try to understand that this is exactly why your code is crashing.
«_Superman_»
|
|
|
|
|
Are you using VC6.0 Advanced Auto-Deferencing Compiler ? lol just kidding.
|
|
|
|
|
py2 is an int * , not an int ** . Extra dimensions of arrays DO NOT imply extra indirection (i.e. extra levels of pointer).
Therefore your C cast when assigning py2 to pyp2 is breaking the type safety that's trying to tell you what your mistake is.
|
|
|
|
|
argh okay. accepted. is there way I can do it? I think it can be done by allocating a memory of that dimension dynamically and assigning the pointers one by one.bullshit. I meant assigning the pointers.
modified on Wednesday, February 4, 2009 4:02 AM
|
|
|
|
|
Try initialising pyp2 like this:
int p1[2] = { 1, 2 };
int p2[2] = { 1, 2 };
int* pyp2[2] = { p1, p2 };
pyp2 is of type (int*)[2] , which is equivalent to int ** .
|
|
|
|
|
hmm, so we cannot simply take a pointer and navigate through.. .. the complier wants it to be informed about these..
|
|
|
|
|
I think I just ripped through mr.Smith
tried this :
<br />
int py2[2][2] = {10,11,12,13};<br />
<br />
int* sptr = &py2[0][0];<br />
int** dptr = &sptr;<br />
<br />
printf("\nAtlast:%d\n",**dptr);<br />
*dptr+=1;<br />
*dptr+=2;<br />
printf("\nAtlast:%d\n",**dptr);<br />
o/p:10,13
-Anderson. .
|
|
|
|
|
The key point is that arrays and pointers are NOT the same.
An array can be converted into a pointer and pointer arithmetic (and indexing) looks the same as array subscripting, but they aren't. They coincide only for linear indexing (that's the case of monodimensional arrays)
int **pyp2 is a "[pointer to a [pointer to [an int]]]"
The memory layout it expects is like
int** ----> [int*, int*, int*, ...]
| | |
| | |
| | V
| V [int,int,...]
V [int,int,int...]
[int, int, ...]
While int py2[2][2] is an "[array of [array of [int]]]"
The memory layout it expects is like
[[int,int],[int,int]]
That's completely different.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|