I am trying to do an exercise that tests if there is some blank before a string and removes it if it does, however it is returning the following error:
Targeting failure (recorded core image)
I can not understand why.
Code:
#include <stdio.h>
void removerEspacosEsquerda(char string[]) {
int i, j, cont;
char *string2, a;
i = 0;
cont = 0;
while(string[i] != 0) {
if(string[i] == ' ') {
cont++;
}
i++;
}
i = 0;
j = 0;
printf("%d", cont);
while(string[i] != 0) {
if(i >= cont) {
string2[j] = string[i];
}
i++;
j++;
}
string = string2;
}
int main() {
char *string;
string = " teste";
removerEspacosEsquerda(string);
printf("%s", string);
}