In this tutorial, we will be discussing a program to convert the ASCII value sentence to its equivalent string.
For this we will be provided with a string containing the ASCII codes. Our task is to convert the given string into the equivalent characters and print it back.
Example
#include <bits/stdc++.h>
using namespace std;
//converting the ASCII sequence into
//character string
void convert_ASCII(string str, int len){
int num = 0;
for (int i = 0; i < len; i++) {
//appending the current digit
num = num * 10 + (str[i] - '0');
//checking if number is within range
if (num >= 32 && num <= 122) {
char ch = (char)num;
cout << ch;
num = 0;
}
}
}
int main(){
string str = "104101108108111443211911111410810033";
int len = str.length();
convert_ASCII(str, len);
return 0;
}Output
hello, world!