When I run this code I get an error segmentation fault (core dumped). I see that the error lies in " printf("%c", first(s));", it seems that it is not the correct way to pass char/string to function? if not then what is the problem with my code?
#include <stdio.h>
char first(char *str);
char first(char *str){
int L=0;
int a[127]={0};
for (int i=0; i<127; i++){
a[i]=i+1;
}
while (str != '\0'){
for(int d=1; d<127; d++){
if(str[L]==(char)d){
if (a[L]>0){
a[L]=0;
L++;
break;
}
else if(a[L]==0){
a[L]=-1;
L++;
break;
}
else{
L++;
break;
}
}
}
}
for(int i=0; i>127; i++){
if(a[i]==0)
return (char)(i+1);
}
return '\0';
}
int main()
{
char s="blazqnqbla";
printf("%c", first(s));
return 0;
}
coredump is very probably not from your compiler, but when running the executable produced by compiling your source code. The bug is inside your program, not in the compiler. Read how to debug small programs - Basile Starynkevitchchar s="blazqnqbla";tochar *s="blazqnqbla";- Rishikesh Raje-Wall -Wextra -pedantic. - Paul Rooney