I am getting segmentation fault to this code to convert roman numerals to numbers, i am getting segmentation error when i try the program in https://www.programiz.com/cpp-programming/online-compiler/ and i found that the inside of the loop A is never executed in my case
#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
char str[50];
int a[50],m=50,val=0;
int intit(){
m=strlen(str);
for(int i=0;i<m;i++){//loop A
cout<<i;
if(str[i]=='M'){a[i]=1000;}
if(str[i]=='D'){a[i]=500;}
if(str[i]=='C'){a[i]=100;}
if(str[i]=='L'){a[i]=50;}
if(str[i]=='X'){a[i]=10;}
if(str[i]=='V'){a[i]=5;}
if(str[i]=='I'){a[i]=1;}
}
return 0;
}
int main(){
char str[50];
int a[50],m,val=0;
cin>>str;
cout<<"exit val" +char(intit());
for(int i=m-1;i>=0;i--){ //loop B
cout<<"inside evaluation loop"<<a[i];
if(a[i+1]>a[i]){val = val - a[i];}
else{val = val + a[i];}
}
cout<<"\n\n\nans:"<<val;
getch();
}