plz help me to remove SIBABRT error for the following code,plz suggest me why this error occurs even after getting correct output
#include<stdio.h>
#include<string.h>
int main()
{
char x[25],y[25];
int i,j=0;
scanf("%s",x);
for(i=0;i<strlen(x);i++)
{
if(x[i]>=97 && x[i]<=122)
{
y[j]=x[i]-32;
j++;
}
else if(x[i]>=65 && x[i]<=90)
{
y[j]=x[i]+32;
j++;
}
}
printf("%s",y);}
If the input is less than 25 characters, then the string will be null terminated. If the size exceeds the array size specified then it overwrites the memory not belonging to the array.
So
fgets()
is the alternative forscanf()
in such case.