My bad in not being clear. I only meant it is possible to know the
size of strings without traversing them as compiler does that but I am
not sure if is it possible for APIs to do the same. Compiler writes
that size in some memory location and use it during delete []str

On Tue, Jul 12, 2011 at 10:54 PM, saurabh singh <saurab...@gmail.com> wrote:
> can strlen do the same job?
> I doubt.......?
>
> On Tue, Jul 12, 2011 at 10:51 PM, Navneet Gupta <navneetn...@gmail.com>
> wrote:
>>
>> @Saurabh, just to let you know, compiler actually does that. Without
>> traversing the array (read specifying the array size), you are able to
>> free up all the memory being consumed by simply writing delete []a.
>>
>>
>> On Tue, Jul 12, 2011 at 10:13 PM, saurabh singh <saurab...@gmail.com>
>> wrote:
>> > and how would strlen compute the length without traversing through the
>> > array?
>> >
>> > On Tue, Jul 12, 2011 at 2:48 PM, sagar pareek <sagarpar...@gmail.com>
>> > wrote:
>> >>
>> >> One solution can be in one traversal :-
>> >>
>> >> take an example:- char str[]="hello my friends"; int i=strlen(str),j=i;
>> >> char *srt1=malloc(sizeof(char)*i);
>> >> 1. start from end of string (while i>=0,i--)
>> >> 2. whenever u find any space do
>> >>    a. strcat(srt1,&srt[i]);
>> >>    b. srt[i]='\0';
>> >>    d. srt[j-i]='<space>'; //replacing nulls by space, can be done using
>> >> strlen(srt1) also
>> >>
>> >> Note:- I have not executed the code so modifications may be needed. :)
>> >>
>> >> On Thu, Jul 7, 2011 at 10:58 PM, Piyush Kapoor <pkjee2...@gmail.com>
>> >> wrote:
>> >>>
>> >>> char a[20];
>> >>> int l,i,j,k;
>> >>> int main()
>> >>> {
>> >>>     char str[100];
>> >>>     gets(str);
>> >>>     l=strlen(str);
>> >>>     for(i=l-1;i>=0;){
>> >>>     k=19;
>> >>>     a[k]='\0';
>> >>>     while(i>=0 && str[i]!=' '){
>> >>>         a[--k]=str[i--];
>> >>>     }
>> >>>     printf("%s",a+k);
>> >>>     while(i>=0 && str[i]==' ') i--;
>> >>>     printf(" ");
>> >>>     }
>> >>> }
>> >>> On Thu, Jul 7, 2011 at 10:37 PM, Piyush Kapoor <pkjee2...@gmail.com>
>> >>> wrote:
>> >>>>
>> >>>> Pls Ignore my above post..
>> >>>>
>> >>>> On Thu, Jul 7, 2011 at 10:36 PM, Piyush Kapoor <pkjee2...@gmail.com>
>> >>>> wrote:
>> >>>>>
>> >>>>> char a[20];
>> >>>>> int l;
>> >>>>> int main()
>> >>>>> {
>> >>>>>      char str[100];
>> >>>>>      scanf("%s",str);
>> >>>>>      l=strlen(str);
>> >>>>>
>> >>>>> }
>> >>>>> --
>> >>>>> Regards,
>> >>>>> Piyush Kapoor,
>> >>>>> CSE-IT-BHU
>> >>>>
>> >>>>
>> >>>>
>> >>>> --
>> >>>> Regards,
>> >>>> Piyush Kapoor,
>> >>>> CSE-IT-BHU
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Regards,
>> >>> Piyush Kapoor,
>> >>> CSE-IT-BHU
>> >>>
>> >>> --
>> >>> You received this message because you are subscribed to the Google
>> >>> Groups
>> >>> "Algorithm Geeks" group.
>> >>> To post to this group, send email to algogeeks@googlegroups.com.
>> >>> To unsubscribe from this group, send email to
>> >>> algogeeks+unsubscr...@googlegroups.com.
>> >>> For more options, visit this group at
>> >>> http://groups.google.com/group/algogeeks?hl=en.
>> >>
>> >>
>> >>
>> >> --
>> >> Regards
>> >> SAGAR PAREEK
>> >> COMPUTER SCIENCE AND ENGINEERING
>> >> NIT ALLAHABAD
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Algorithm Geeks" group.
>> >> To post to this group, send email to algogeeks@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> algogeeks+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/algogeeks?hl=en.
>> >
>> >
>> >
>> > --
>> > Saurabh Singh
>> > B.Tech (Computer Science)
>> > MNNIT ALLAHABAD
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > 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 algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT ALLAHABAD
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to