You can also free the memory of q , we don't need it anymore .
but , the code is just fine .
On Feb 13, 5:03 pm, dinesh bansal bansal...@gmail.com wrote:
On Tue, Jan 11, 2011 at 10:14 PM, snehal jain learner@gmail.com wrote:
what is the wrong in the program?
main()
{
char *p,*q;
main()
{
char *p,*q;
strcpy(p,amazon);
strcpy(q,hyd);
strcat(p,q);
printf(%sp);
}
this snippet also execute to result with no errors.
but it will have some problem with the internal memory, that it may
overwrite the existing space.
so, the given code doesn't have any error in it as the memory
@avpostnikov
In my reply I meant TCHAR ( maybe it doesnt apply to the example given in
the problem)
when your project is being compiled as Unicode, the TCHAR would translate to
wchar_t. If it is being compiled as ANSI/MBCS, it would translated to char
Not always we explicitly use wchar_t.
On
Apart from that ,
In Unicode application each char would be 2 bytes in length and its always
advisable to use malloc(sizeof(char) * 25) which seamlessly works fine in
ASCII application as well.
On Wed, Jan 12, 2011 at 7:20 AM, Kiran K kira...@gmail.com wrote:
p= (char*)malloc(25);
KK: p
what is the wrong in the program?
main()
{
char *p,*q;
p=(char *)malloc(25); // check p==null
q=(char *)malloc(25);//check q == null
strcpy(p,amazon);
strcpy(q,hyd);
strcat(p,q);
printf(%sp);
}
--
You received this message because you are subscribed to the Google
@Harish
You are wrong. It doesn't matter when it is Unicode or ASCII application.
Size of the char type is ALWAYS 1 byte.
To use unicode characters introduce wchar_t or something related.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To
p= (char*)malloc(25);
KK: p should be checked for null after this statment
q = (char*)malloc(25);
KK: q should be checked for null after this statement
-Kiran
On Jan 11, 9:44 pm, snehal jain learner@gmail.com wrote:
what is the wrong in the program?
main()
{
char *p,*q;
p=(char