The below code is not showing any output after running, But on debugging it is showing Segmentation fault inside 3rd if statement 1st line string[index] = string[i];
please help why it is happening,
Please explain in simple words, Thanks a lot.
#include <stdio.h>
#include <string.h>
void parse(char *string);
int main() {
char *html = "<h1> This is html heading </h1>";
parse(html);
printf("%s", html);
return 0;
}
void parse(char *string) {
int index = 0;
int inside;
for (int i = 0; i < strlen(string); i++) {
if (string[i] == '<') {
inside = 1;
continue;
}
else if (string[i] == '>') {
inside = 0;
continue;
}
if (inside == 0) {
string[index] = string[i];
index++;
}
}
string[index] = '\0';
}
Expected output
" This is html heading "