my teacher told us to write a program that should give the length of a string after taking out the consecutive spaces, and only use one space. for example, if i write "hello(space)(space)(space)world" it should return "hello world" and the length should be 11. The problem is that i keep getting segmentation fault and i don't know why? can someone explain it to me? thanks by the way!
int limpaEspacos (char t[]){
int i, j, w=0;
char c;
for(i=0;t[i];i++){
t[w]=t[i];
w++;
for(j=i;t[j];j++,i++){
if (t[j]!=' ') {break;}
}
}
t[w]='\0';
return w;
}
int main () {
int a;
a= limpaEspacos ("b ruh");
printf("%d\n", a );
return 0;
}