its still buggy,,,.....The problem is with the sprintf function....It
appends *null character too.*I dont think you are taking this into
consideration.Write your own routine for the same.Its not a hard job and it
will be worth the effort.

Input:
acbaaxa

your program's output

acba2

*Just fix the sscanf thing.Shortcuts always lead to bugs...:)*
(Apologies if I am wrong)

On Tue, Aug 9, 2011 at 9:41 PM, sagar pareek <[email protected]> wrote:

> @saurabh
> ur all test cases have count for each character >9 thats why its
> overwriting the second digit ....
>
> modified code is:-
>
> #include<stdio.h>
> #include<string.h>
>
> main()
> {
>  int i,j=0,l,count;
>  char str[100],tmp;
>
>  printf("Please enter the string\n");
>  fgets(str,100,stdin);
>
>  l=strlen(str);
>  tmp=str[0]; count=1;
>
>  for(i=1;i<=l;i++)
>  {
>    if(tmp==str[i])
>    { count++; printf("count=%d\n",count); }
>    else
>    {  if(count==1) str[j++]=tmp; else{ str[j++]=tmp;
> sprintf(&str[j++],"%d",count); if(count>9) j++; } count=1; tmp=str[i]; }
>  }
>   //str[j++]=tmp; sprintf(&str[j++],"%d",count);
>   str[j]='\0';
>
>  printf("%s\n",str);
> }
>
>
> Now it has no bug
>
>
> On Tue, Aug 9, 2011 at 8:53 PM, Dipankar Patro <[email protected]>wrote:
>
>> Here is my code:
>> http://ideone.com/deosU
>>
>> Same as that of Sagar's :D
>> time O(n) and space O(1)
>>
>>
>>
>> On 9 August 2011 20:25, siddharam suresh <[email protected]> wrote:
>>
>>> saurabh
>>> test my program
>>> please tell me if any bug is there
>>> Thank you,
>>> Siddharam
>>>
>>>
>>>
>>> On Tue, Aug 9, 2011 at 8:18 PM, saurabh singh <[email protected]>wrote:
>>>
>>>> The code failed for all test cases I tried.....
>>>>
>>>>
>>>> On Tue, Aug 9, 2011 at 8:15 PM, ankit sambyal 
>>>> <[email protected]>wrote:
>>>>
>>>>> ya got it now. I misunderstood the question
>>>>>
>>>>> --
>>>>> 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.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> 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 [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.
>>>
>>
>>
>>
>> --
>>
>> ___________________________________________________________________________________________________________
>>
>> Please do not print this e-mail until urgent requirement. Go Green!!
>> Save Papers <=> Save Trees
>>
>>  --
>> 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
> 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 [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.
>



-- 
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 [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