runtime error when test case is more than 1(chef and codes)

#include<stdio.h>
//#include<conio.h>
#include<string.h>
#include<ctype.h>

typedef struct string
{
 char c,map;
 int occ;
}string;
string s[26];
void swap(int i,int j);

int main()
{
 //clrscr();
 char eng[26],ip[150001],ip1[150001],ip2[150001],ch,cha;
 int l,k,i,j,m,t,n,r=0;
 scanf("%d",&t);
 for(n=0;n<t;n++)
 {
 scanf("%s %[^\n]%c",eng,ip);
 strcpy(ip1,ip);
 l=strlen(ip);
 k=0;
 for(i=0;i<26;i++)
 s[i].occ=0;
 for(i=0;i<l;i++)
 {
  if(isalpha(ip[i]))
  {
   s[k].c=tolower(ip[i]);
   s[k].occ++;
   for(j=i+1;j<l;j++)
   {
    ch=tolower(ip[j]);
    if(isalpha(ch)&&s[k].c==ch)
    {
     ip[j]='0';
     s[k].occ++;
    }
   }
  k++;
  }
  m=k;
 }
 eng[26]='\0';

 for(i=0;i<k;i++)
 {
  for(j=i+1;j<k;j++)
  {
   if(s[i].occ==s[j].occ&&s[i].c>s[j].c)
   swap(i,j);
   else if(s[i].occ>s[j].occ)
   swap(i,j);
  }
 }

 j=strlen(eng)-1;
 for(i=k-1;i>=0;i--)
 s[i].map=eng[j--];

 for(i=0;i<l;i++)
 {
  ch=tolower(ip1[i]);
  for(j=0;j<k;j++)
  {
   if(ch==s[j].c)
   {
    cha=toascii(ip1[i]);
    if(cha>=65&&cha<=90)
     ip1[i]=toupper(s[j].map);
    else
     ip1[i]=s[j].map;
    }
   }
  }
  for(m=0;m<l;m++)
  ip2[r++]=ip1[m];
  ip2[r++]='\n';
 }
   ip2[r]='\0';
printf("%s",ip2);
//getch();
return 0;
}
  void swap(int i,int j)
  {
   string temp;
   temp=s[i];
   s[i]=s[j];
   s[j]=temp;
  }

i ran this code on ideone and it gives Runtime error time: 0 memory: 2248 signal:11 if we enter test case more than 1.
I am not getting this.Please help me out.

Are you happy with the following LOC

scanf("%s %[^\n]%c",eng,ip);

Perhaps you want a *[^\n]%s or gets.
I did not look any further but this looks like the culprit.

1 Like

you were right :slight_smile:
something was wrong with that.
So scanf("%s %[^\n]s",eng,ip); did the trick for me :)thankyou :slight_smile: