Help needed in debugging (ascii difference problem)

include
#include
#include

using namespace std;
int main()
{
string a;
getline(cin, a);

int i, j;
for(i = 0; a[i] != '\0'; i++)
{
    char diff = a[i+1]-a[i]+'0';
    for( j = strlen(a)+1; j >= i+1; j--)
        a[j] = a[j-1];
    a[j+1] = diff;
}
cout << a;

return 0;

}
It is showing error on the line for(j = strlen(a)+1; j>= i+1; j–)
Moreover, could you please that is it the correct code for ascii difference problem?

hey @utkarshvashisth94 the problem is that stlen() accepts a character array but you are passing it a string object which are two different things, i would suggest you to construct a new string for result instead of chaging input string itself, moreover there is problem with indexing as well you need to iterate till second last element not the last element.

@utkarshvashisth94 please refer to this code if you are unable to make the required changes

1 Like

Thanks for help @keshavgupta0103.