u r rite..but now tht prblem is solved the problem i am facing to
submit the code is that it does not print the code in lexicographical
order...

On May 16, 1:56 pm, "Dhruva Sagar" <[EMAIL PROTECTED]> wrote:
> str[n]=NULL;
> I think it should be str[n-1]='\0'; (String null character).
> And the loop should run from i=0;i<n-1.
> The memory allocated would be of size n, i.e. 0 to n-1. str[n] would be
> outside the allocated memory...
>
> Correct me if i m wrong.
>
> ---------- Forwarded message ----------
> From: mirchi <[EMAIL PROTECTED]>
> Date: May 16, 2007 2:20 PM
> Subject: [algogeeks] Re: acm problem : i need help
> To: Algorithm Geeks <algogeeks@googlegroups.com>
>
> that problem is solved..but now the reply is "wrong answer".
> the problem asks for printing the strings in ascending lexicographical
> order.
> wat does this mean??
>
> On May 16, 12:55 pm, "Yingjie Xu" <[EMAIL PROTECTED]> wrote:
> > a c style string with length n needs n+1 memory space.
>
> > On 5/16/07, mirchi <[EMAIL PROTECTED]> wrote:
>
> > > hello people ,
> > > i am facing a problem in submission of "The Hamming Disteance "
> > > problem. the output seems to be fine. but the program crashes in
> > > between. the error says:
>
> > > The instruction at "0x7c93426d" referenced memory at "0x00000000" .
> > > The memory could not be "read" .
>
> > > and the acm feedback error says :
>
> > > Your program has died with signal 11 (SIGSEGV). Meaning:
>
> > >   Invalid memory reference
>
> > > Before crash, it ran during 0.004 seconds.
>
> > > the code is as below :
>
> > > #include<stdio.h>
> > > #include<stdlib.h>
> > > void func (int k , int m , int r , int n , char *str , int count);
> > > int main()
> > > {
> > >    int i,count=0;
> > >    int noi,ij;
> > >    int r,n;
> > >    char *str;
> > >    scanf("%d",&noi);
> > >    for(ij=0;ij<noi;ij++)
> > >    {
> > >           scanf("%d %d",&n,&r);
> > >           str=(char *)malloc(sizeof(char)*n);
> > >           for(i=0;i<n;i++)
> > >           {
> > >                    str[i]='0';
> > >           }
> > >           str[n]=NULL;
> > >           func(0,n-r,r,n,str,count);
> > >    }
> > >    return 0;
> > > }
> > > void func (int k , int m , int r , int n , char *str,int count)
> > > {
> > >    int i,j ;
> > >    if(count==(r-1))
> > >    {
> > >              for(j=k;j<n;j++)
> > >              {
> > >                              str[j]='1';
> > >                              if(j!=k)
> > >                              str[j-1]='0';
> > >                              printf("%s\n",str);
> > >              }
> > >              str[j-1]= '0';
> > >              return ;
> > >    }
> > >    else
> > >    {
> > >              for(i=k;i<=m;i++)
> > >              {
> > >                              str[i]='1';
> > >                              if(i!=k)str[i-1]='0';
> > >                              func(i+1,m+1,r,n,str,count+1);
> > >              }
> > >    }
> > > }
>
> > > thanx in advance !
>
> --
> Thanks & Regards,
> Dhruva Sagar.


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to