|
What error do you get [Compile/RunTime]. Please provide the details
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Thnaks for your reply
I am getting an runtime error...
(Unhandled exception...Access violation)
Thanks...(anyway,..My brothers name is Anshumaan)
-----------------------------
I am a beginner
|
|
|
|
|
Ah! that may be because temp is not initialized.
Initialize it!
And believe it or not, but my brothers name is HIMANGSHU
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
thanks a lot...
About the name..that's interesting...I feel somewhat to talk personal staff in this forum. Lets not violet the rules..hehe...Could you give me Gmail Id if you dont mind.We can talk in Gtalk .
Regards,
Himangshu
|
|
|
|
|
What error? I cannot see syntactic error there. Do you allocate memory for temp?
|
|
|
|
|
I am getting an runtime error...
(Unhandled exception...Access violation)
|
|
|
|
|
You should must allocate memory for temp .
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]
|
|
|
|
|
thanks
But there is one problem. How much memory should I allocate? Since It is a program for concatenation of string...And I wont be knowing the no of characters after contcatination(ie the size of the temp) in advance.
How to go about it?
|
|
|
|
|
Well you may allocate a predefined amount of memory (on statistical grounds) and then reallocate (for instance, in C language, you may use malloc and realloc ) a bigger size if needed.
BTW: you know, there are C runtime library functions for the purpose of concatenating strings.
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]
|
|
|
|
|
yes But I wanted to implement it with my own code....So that I learn pointer concept too..
-----------------------------
I am a beginner
|
|
|
|
|
I used the following code.....No error but not giving any results
char *a,*b;
char *temp;
temp=new char[5];
a="aa";
b="bb";
while(*a!='\0')
{
*temp++ =*a++ ;
}
while(*b!='\0')
{
*temp++= *b++ ;
}
*temp = '\0';
printf("%s",temp);
-----------------------------
I am a beginner
|
|
|
|
|
That's almost the solution... , try:
char *a,*b;
char *temp, *dest;
dest=new char[5];
temp = dest;
a="aa";
b="bb";
while(*a!='\0')
{
*temp++ =*a++ ;
}
while(*b!='\0')
{
*temp++= *b++ ;
}
*temp = '\0';
printf("%s",dest);
of course you need now to generalize the code (ad remember to free dest when you no longer need it)
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]
|
|
|
|
|
Oh thanks a lot...its working fine...
I have to increase my knowledge towards pointer
-----------------------------
I am a beginner
|
|
|
|
|
himangshuS wrote: I wont be knowing the no of characters after contcatination(ie the size of the temp) in advance.
Yes you can - you need to allocate strlen(A) + strlen(B) + 1 characters, where strlen is defined as follows:
int strlen(const char* s)
{
int count;
while (*(s++))
++count;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
A code you have past here is the exact code that is in your system?
But if you have taken temp as array (char temp[XX] ) then you might get error which you told. But a code that we are sawing has no that kind of error.
Do not trust a computer...
Always check what computer is doing
regards,
Divyang Mithaiwala
Software Engineer
modified on Thursday, May 7, 2009 5:38 AM
|
|
|
|
|
Sure?
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]
|
|
|
|
|
Divyang Mithaiwala wrote: Because if you have taken temp as array (char temp[XX]) then you might get error
Why so?
Divyang Mithaiwala wrote: But a code that we are sawing has no that kind of error.
Did you trust your computer to check if there was a runtime error?
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
sorry, But I really didnot get that
-----------------------------
I am a beginner
|
|
|
|
|
When I was posted I haven't seen your clarification that you are facing run time error (due to no refresh page).
So, If you have taken variable as char temp[10]; and try to execute
*temp++ = *a++;
it will give you compile time error.
Do not trust a computer...
Always check what computer is doing
regards,
Divyang Mithaiwala
Software Engineer
|
|
|
|
|
I haven't tested that nor tried something similar, but I think that the hole think wont give you the right result anyway.
By incrementing the char * temp it jumps to the next position and you will lose the previous position, don't you?
So if you really want to do something like that you should have a pointer to the first position of temp (I guess).
So why not simply allocate mem for temp and then do a memcpy with a and b? Given memcpy temp and for b &temp[2] for example.
I hope this will do the trick, but I am just guessing.
Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
|
|
|
|
|
I have delphi application .I am trying to convert it into c++ builder
this is my delphi function
function TClipCollection.GetItem(Index: Integer): TClipItem;
begin
Result := inherited Items[Index] as TClipItem;
end;
and this is my builder function
TClipItem TClipCollection::*GetItem(int Index)
{
// Result := inherited Items[Index] as TClipItem;
how i convert this line
}
|
|
|
|
|
Probably something like
TClipItem* TClipCollection::GetItem(int Index)
{
return (TClipItem*)Items[Index];
}
You need to be sure that the array indices are consistent between Delphi and C++ (C++ array indices start at zero - do Delphi array indices do the same?).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
thanks Stuart Dootson
but i am now getting error
E2451 Undefined symbol 'Items'
where as i defined the property in the TClipCollection class
__property TClipItem *Items[int Index] = { read=GetItem, write=SetItem};
for more details my class like this
class TClipCollection : public TCollection
{
private:
TClipItem *GetItem(int Index);
void SetItem(int Index,TClipItem *Value);
public:
TClipCollection();
__property TClipItem *Items[int Index] = { read=GetItem, write=SetItem};
TClipItem Add();
TClipCollectionEnumerator GetEnumerator();
};
|
|
|
|
|
How are you using Items? It looks to me like the compiler and linker are seeing Items as a global symbol (i.e. not a class member).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
but in delphi it is used
delphi code is this
TClipCollection = class(TCollection)
private
function GetItem(Index: Integer): TClipItem;
procedure SetItem(Index: Integer; const Value: TClipItem);
public
constructor Create;
property Items[Index: Integer]: TClipItem read GetItem write SetItem; default;
function Add: TClipItem;
function GetEnumerator: TClipCollectionEnumerator;
end;
you r right and when i mke the constructor of this class then i got also error
E2251 Cannot find default constructor to initialize base class 'TCollection'
then what i do for this
|
|
|
|