runtime error (SIGSEGV)

#include<stdio.h>
int stringLength(char *s);
void printString(char *s);
void noVowelString(char *s);
void stringAppend(char *s1,char *s2);
int process(char *r);
void stringCompare(char *s1,char *s2);
int main()
{
int t,c1,c2,a,i;
char input[10],string[15],str[30],*s,*s1,s2;
scanf("%d",&t);
for(c1=1;c1<=t;c1++)
{
scanf("%s",input);
a= process(&input[0]);
if( a == 1 || a == 2)
{ scanf("%s",string);
s= &string[0];
if(a==1) {printString(s);}
if(a==2) {noVowelString(s);}
}
if( a == 3 || a == 4)
{ scanf("%s",str);
scanf("%s",string);
s1 = &str[0]; s2 = &string[0];
if(a==3) {stringAppend(s1,s2);}
if(a==4);{stringCompare(s1,s2);}
}
}
return 0;
}
int stringLength(char s)
{
int n;
for(n=0;
(s+n) != ‘\0’;n++) ;
return (n);
}
void printString(char s)
{
int n;
for(n=0;(s+n) != ‘\0’;n++)
printf("%c",
(s+n));
}
void noVowelString(char s)
{
int l,n,t=0,m;
l = stringLength(s);
for(n=0;
(s+n) != 0;n++)
{
if(
(s+n) == ‘a’ || *(s+n) == ‘e’ || *(s+n) == ‘i’ || *(s+n) == ‘o’ || *(s+n) == ‘u’ || *(s+n) == ‘A’ || *(s+n) == ‘E’ || *(s+n) == ‘I’ || *(s+n) == ‘O’ || (s+n) == ‘U’)
{
for(m=n;
(s+m+1) != 0;m++)
{
*(s+m) = *(s+m+1);
}
t += 1;
*(s+l-t) = ‘\0’;
n = n - 1;
}
}
printString(s);
}
void stringAppend(char *s1,char s2)
{
int l1,n;
l1 = stringLength(s1);
for(n=0;
(s2+n) != 0;n++)
{
*(s1+l1+n) = *(s2+n);
}
printString(s1);
}
int process(char *r)
{
int a;
if(r == ‘p’)
{ if(
(r+1) == ‘r’ && *(r+2) == ‘i’ && *(r+3) == ‘n’ && *(r+4) == ‘t’ )
a=1;
}
if(r == ‘n’)
{ if(
(r+1) == ‘o’ && *(r+2) == ‘v’ && *(r+3) == ‘o’ && *(r+4) == ‘w’ && *(r+5) == ‘e’ && *(r+6) == ‘l’)
a=2;
}
if(r == ‘a’)
{ if(
(r+1) == ‘p’ && *(r+2) == ‘p’ && *(r+3) == ‘e’ && *(r+4) == ‘n’ && *(r+5) == ‘d’)
a=3;
}
if(r == ‘c’)
{ if(
(r+1) == ‘o’ && *(r+2) == ‘m’ && *(r+3) == ‘p’ && *(r+4) == ‘a’ && *(r+5) == ‘r’ && *(r+6) == ‘e’)
a=4;
}
return (a);
}
void stringCompare(char *s1,char *s2)
{
int l1,l2,i;
l1=stringLength(s1);
l2=stringLength(s2);
if(l1 > l2) {printString(s1);}
if(l1 < l2) {printString(s2);}
if(l1 == l2)
{
for(i=0; *(s1+i) != 0;i++)
{
if( (int) *(s1+i) > (int) *(s2+i) ) {printString(s2);break;}
if( (int) *(s1+i) < (int) *(s2+i) ) {printString(s1);break;}
}
if( i == l1) {printString(s1);}
}
}

1 Like

if anyone is not able to see this code clearly pls browse this page:

Hi, your code isn’t giving runtime error now for the sample input you provided --> [Working code][1]

Just made some modification in the [void printString(char *s)] function.
[1]: http://ideone.com/Bw6Bfm

2 Likes

but i am not supposed to use strlen function in my code.

1 Like

It is a small mistake . I forgot to put * before (s+n). Btw thank you for help.

http://ideone.com/Bw6Bfm Here is your code without using strlen function :slight_smile:

Mention not :slight_smile: