I am writing c++ code to convert ebcdic to ascii
My main() is shown below
int main()
{
char text[100];
int position;
int count;
printf("Enter some text\n");
cin >> text;
char substring[] = "\\x";
if(strlen(text) 2 != 0)
{
cout << "Length of the string is not even" << endl;
}
else
{
position = 1;
int len_string;
len_string = strlen(text)/2;
cout<<"len_string"<<len_string<<endl;
for (count = 0; count < len_string;count++)
{
insert_substring(text, substring, position);
printf("text is s\n",text);
position = position + 4;
}
}
ebcdicToAscii((unsigned char*)text);
cout << "Converted text" <<text << endl;
char str[]="\xF5\x40\x40\x40\x40\xD4"; //Hardcoded string
ebcdicToAscii((unsigned char*)str);
printf ("converted str is s\n", str);
return 0;
}
Output:
Enter some text
F54040404040D4
len_string7
text is \xF54040404040D4
text is \xF5\x4040404040D4
text is \xF5\x40\x40404040D4
text is \xF5\x40\x40\x404040D4
text is \xF5\x40\x40\x40\x4040D4
text is \xF5\x40\x40\x40\x40\x40D4
text is \xF5\x40\x40\x40\x40\x40\xD4
Converted text**?*?*?*?*?*
converted str is 5 M
Before conversion I need to append \x infront of string
Example:
F540404040D4
must be inserting escape sequence \x
I have written the logic so I got the output:
\xF5\x40\x40/x40\x40\xD4
Now conversion of ebcdic to ascii starts using
ebcdicToAscii((unsigned char*)text);
But I am not getting desired output.
At the same time when I hardcode the string as
\xF5\x40\x40/x40\x40\xD4
the output is as expected
i.e 5 M
I am confused. Please Guide me. I have not shown called functions in code assuming that it is giving proper return.