This code throws the EXC_BAD_ACCESS Error when trying to set t[j]
to t[j+1]
and i dont understand why?
#include <stdio.h>
#include <ctype.h>
int strclean(char *t){
int tmp2 = 0;
if(t == NULL){
return -1;
}
int i = 0;
while(t[i] != NULL) {
if (isprint(t[i]) == 0 || isspace(t[i])) {
tmp2++;
for(int j = i; t[j]!=NULL;j++){
t[j] = t[j+1]; //throws error
}
i--;
}
printf("%c\n", t[i]);
i++;
}
t[i] = "\0";
return tmp2;
}
int main() {
printf("%d\n", strclean("fg h ear p\n"));
return 0;
}
thank you for the help in advance!