in my compiler,its giving
0000 is rajeev

 this is string 1
0000 is ra"


On Fri, Jul 8, 2011 at 11:33 AM, rajeev bharshetty <[email protected]>wrote:

> @Vishal : yes I can use strcpy, But What is the problem with memcpy().
>
>
> On Fri, Jul 8, 2011 at 11:27 AM, Vishal Thanki <[email protected]>wrote:
>
>> memcpy is usually used to copy data structures other than strings. Use
>> strcpy for copying strings!!
>>
>> On Fri, Jul 8, 2011 at 11:25 AM, Navneet Gupta <[email protected]>
>> wrote:
>> > @Vishal, still the array str1 is also 10 bytes only, I know that memcpy
>> > overwrites the null character but not sure then what is the correct
>> approach
>> > if i still want to use memcpy. Thoughts?
>> >
>> > On Fri, Jul 8, 2011 at 10:51 AM, Vishal Thanki <[email protected]>
>> > wrote:
>> >>
>> >> you are overwriting terminating null char!!
>> >>
>> >> On Fri, Jul 8, 2011 at 10:23 AM, rShetty <[email protected]> wrote:
>> >> > #include<stdio.h>
>> >> > #include<string.h>
>> >> > int main()
>> >> > {
>> >> >  char str[]="This is rajeev\n";
>> >> >  char str1[10];
>> >> >  memset(str,'0',4);
>> >> >  printf("%s",str);
>> >> >  memcpy(str1,str,10);
>> >> >  printf("\n this is string 1\n");
>> >> >  printf("%s\n",str1);
>> >> >  return 0;
>> >> > }
>> >> >
>> >> > Output is :
>> >> >
>> >> > 0000 is rajeev
>> >> >
>> >> >  this is string 1
>> >> > 0000 is ra0000 is rajeev
>> >> >
>> >> >
>> >> > it copies 10 characters from str to str1 so the printing 0000 is ra
>> is
>> >> > Ok what abt the repeating result?
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups "Algorithm Geeks" group.
>> >> > To post to this group, send email to [email protected].
>> >> > To unsubscribe from this group, send email to
>> >> > [email protected].
>> >> > For more options, visit this group at
>> >> > http://groups.google.com/group/algogeeks?hl=en.
>> >> >
>> >> >
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "Algorithm Geeks" group.
>> >> To post to this group, send email to [email protected].
>> >> To unsubscribe from this group, send email to
>> >> [email protected].
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/algogeeks?hl=en.
>> >>
>> >
>> >
>> >
>> > --
>> > Regards,
>> > Navneet
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to
>> > [email protected].
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Regards,
Kamakshi
[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to