|
Are you completely sure the segfault comes from strcat? How did you determine this (setting breakpoints, putting traces in the code...)?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Because If I add a comment in the strcat() the segmentation fault does not appear and if I take the comment away the segmentation fault appears.
|
|
|
|
|
Hmm...what happens if you increate the string buffer to -let's say- 150 chars? Or increase your stringaux to -let's say- 10 chars? Does anything change? Also, before the strcat, try displaying the 2 strings to see what is in them, printf or puts should do it...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Remember that strlen returns the length without the terminating null character.
|
|
|
|
|
That is not the point!
Even if I am taking care your comment and in the example I change <100 by <99 the problem is not there.
Because as I said before I am sure that the segmentation fault is not because there is not space in the destiny, even if I make bigger the destiny [1000] I still get the segmentation fault.
|
|
|
|
|
strcat() appends source to destination, overwriting the null character. Does string have one?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Probably yes, since strlen appears (or as someone already suspected, maybe that the segmention fault occur before the actual call to strcat ) to succeed.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yeah, I did not bother to fully scrutinize his code. It's possible that stringaux has a '\0' but not within the 3 bytes allocated to it.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: It's possible that stringaux has a '\0' but not within the 3 bytes allocated to it.
But, I suppose, that doesn't harm (it is string the indictee...).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am sure that the problem is in strcat and not in strlen.
|
|
|
|
|
Why?
Could you please post a test case (i.e. the input values for the two string) showing the failure?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Can you tell me, Which compiler you are using?
I have tried with same code given above with gcc compiler in Debian, I doesn't get any Segmentation fault.
Its may be because of your compiler.
I too faced the Same problem when i tried to get the String in run time, in tcc. then later I tried with gcc it worked perfectly..
|
|
|
|
|
Hello,
Can a RUNTIME_CLASS macro have a class with parameters ?
CMDIFrameWnd* pFrame = STATIC_DOWNCAST(CMDIFrameWnd,AfxGetApp()->m_pMainWnd);
CString str = "string";
pFrame->CreateNewChild(RUNTIME_CLASS(TableF(str),IDR_KTYPE, m_hMDIMenu, m_hMDIAccel);
Prithaa
|
|
|
|
|
RUNTIME_CLASS macro will only take class name as parameter.
prvn
|
|
|
|
|
Hello,
Thanks for your reply.
CMDIFrameWnd* pFrame = STATIC_DOWNCAST(CMDIFrameWnd,AfxGetApp()->m_pMainWnd);
CString str = "string";
pFrame->CreateNewChild(RUNTIME_CLASS(TableF(str),IDR_KTYPE, m_hMDIMenu, m_hMDIAccel);
so when I am making this window and I want to pass parameters what should be done.How can I trace the object of this window.
Pritha
|
|
|
|
|
Hey, I am trying to open form2 from form1. Then open a new form1 when form 2 is closed. But adding the #include "Form1.h" header to form2.h is causing errors (undeclared identifier). I added these inclusion guards and tried using forward declaration. EIther that didn't work or I used it wrong because these are the automatically generated code for Forms in the .h file.
/*Form1.h*/
#pragma once
#ifndef First
#define First
#include "Form2.h"
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Form2 ^ frm = gcnew Form2;
frm->Show();
this->Close();
}
#endif
/*Form2.h*/
#pragma once
#ifndef Second
#define Second
#include "Form1.h"
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Form1 ^ frm = gcnew Form1;
frm->Show();
this->Close();
}
#endif
|
|
|
|
|
You should post this question in the Managed C++ forum.
|
|
|
|
|
As Cedric said, there is a managed C++ forum - and you should be using it.
But in C/C++, this would work:
class CTwo;
class COne
{
...
CTwo *m_pTwo;
CTwm m_Two;
};
class Two
{
...
COne *m_pOne;
COne m_One;
};
I hope that helps,
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
|
1/ It's a codeguru article - did you get any luck on codeguru's forums?
2/ I've had good success with a codeproject article:
http://www.codeproject.com/KB/miscctrl/colour_picker.aspx[^]
3/ I've written my own combobox like control, where you can put anything you like in the little boxes...
http://www.codeproject.com/KB/miscctrl/generic_picker.aspx[^]
4/ If you look at the code on the original codeguru article, you'll see it handles WM_DRAWITEM, and there will be a couple of lines where it draws the coloured box - just replace that with your own code.
5/ Didn't I already point you at our combobox section? We have several other owner draw combo boxes that you can learn from.
6/ Good luck!
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
hey guys my project is about how to limit the download and the upload from the internet, and it will be run on a server connected on many pcs, so the server will organize the limit of each pc, and manage the download and upload, and if one exceed it limit it sends a warrning message.
But i face a problem during implementation in c++, first i used the buffer to control the limit, but i don t know how i can know if any pc use the internet browser to download or upload and how i can get the data from the internet browser and transfer it to bytes and store it in the buffer:
this is my code:
setlimit(int limit, int nbofpc)
{
Float limitbypc;
Limitbypc = limit/nbofpc;
For(int i=0; i<nbofpc;i++)>
Char buffer limitbypc;
Return 0;
}
if(download)
{
void downloadlimit( )
{ AnsiString IP;
For(int i=0; i<nbofpc;>Switch (IP)
{Case ‘10.15.1.157’: bufferlimitbypc = fputs(data);
If(sizeof(data)) == sizeof(buffer)
WriteString ("you can’t download more"); break;
Case ’10.15.1.158’: bufferlimitbypc = fputs(data); break;
If(sizeof(data)) == sizeof(buffer)
WriteString ("you can’t download more"); break;
……………
Case’10.15.1.164’: ……….; break;
}
}
Return 0;}}
if(upload)
{
void uploadlimit( )
{ AnsiString IP;
For(int i=0; i<nbofpc;>Switch (IP)
{Case ‘10.15.1.157’: bufferlimitbypc = fputs(data);
If(sizeof(data)) == sizeof(buffer)
WriteString ("you can’t upload more"); break;
Case ’10.15.1.158’: bufferlimitbypc = fputs(data); break;
If(sizeof(data)) == sizeof(buffer)
WriteString ("you can’t upload more"); break;
……………
Case’10.15.1.164’: ……….; break;
}
}
Return 0;}}
thanks
joseph
|
|
|
|
|
So you have a plan and have made some assumptions. The assumptions are without form and the Plan is completely without substance. The darkness is upon those that read your post. Verily we say unto you:
"It is a crock of sh*t, and it stinketh".
"It is a pail of dung and none may abide by the odor thereof."
|
|
|
|
|
Haven't you already asked this same question twice already? Could it be that no one has an answer/solution? Could it be that not everyone has had a chance to see it (CP is accessed by folks all over the globe)? What language is it in? While it will unlikely make any difference as to whether you receive a response or not, you might consider formatting the code snippet so that it is more pleasing to the eyes. Folks help out for free here in their own time. Not having to spend time deciphering code is considered a plus.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
while without a third-party software
|
|
|
|
|
I think it's not supported.
You can right click on #include statement and opt for "Open Document" menu
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|