Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

紧急求救!快来帮帮我!

1 view
Skip to first unread message

question

unread,
Feb 2, 2010, 6:30:25 PM2/2/10
to
���������ڴ���һ����ε��õĺ�����������ҪΪ����ʾ������ַ����ڵ�����B����200��κ󣬴���IJ����У��ַ�ͱ�ɿ��ˣ����ҿ��ˣ��������������ǶԵġ�������A�п�ʱ����B(...)����s[]��ֻ��s[0]�ǿ�ֵ�����s[]����Ҳ���ԣ�����Ϊʲô�أ��Ҹ���ν���أ����ҿ�������Ұɣ������ڳ����ϱ��?��û����BOSS�����ˣ�555...

void A(..)
{
...
CString s[10];
s[0].Format("%d",i);
.....
B(struct��float, float, int, int, char[50],int);
//ע��˴�����д��char[50]����Ϊ����LPCSTR����LPSTR��s[0]
...
return 0;
}

void B(struct��float, float, int, int, char[50],int)
{
...
��ȡ����char[50]��������ִ��A����200��κ�Ͳ����ˣ��˴�Ϊ�գ�����Ϊʲô�أ��ҵ��������д��أ����Ѿ�����þ��ˡ�����ֿ�������ң�
...
}


韩冲

unread,
Apr 10, 2010, 7:02:01 AM4/10/10
to
数组分配的是栈内存吧,每次执行时会覆盖数组中的数据,你用应该用堆内存:
void A()
{
char *s = new char(1024);
ZeroMemory(s,1024);
sprintf(s,"%d",i);
b(s);
delete [] s;
}
void b(char *s)
{
}

"question" <mi...@mycompany.com> 写入消息
news:#PUz1#FpKHA...@TK2MSFTNGP06.phx.gbl...
> 下面是我在处理一个多次调用的函数做法,主要为了显示传入的字符串,但在调用了B函数200多次后,传入的参数中,字符串就变成空了,但我看了,其他几个传入参数都是对的。而我在A中看时,在B(...)处,s[]中只有s[0]是空值,别的s[]内容也都对,这是为什么呢?我该如何解决呢?请大家快来帮帮我吧!我现在程序老报错,都没法跟BOSS交差了,555...


>
> void A(..)
> {
> ...
> CString s[10];
> s[0].Format("%d",i);
> .....
> B(struct,float, float, int, int, char[50],int);

> //注意此处我填写的char[50]内容为,(LPCSTR)(LPSTR)s[0]


> ...
> return 0;
> }
>
> void B(struct,float, float, int, int, char[50],int)
> {
> ...

> 获取到的char[50]参数在正常执行A函数200多次后就不对了,此处为空,这是为什么呢?我到底哪里有错呢?我已经纠结好久了。请高手快来帮帮我!
> ...
> }
>
>

0 new messages