C Program to String containing words forming a sentence convert to equivalent ASCII Sentence

  • Given a string containing words forming a sentence (belonging to the English).
  • The task is to output the equivalent ASCII sentence of the input sentence.
  • ASCII form of a sentence is the conversion of each of the characters of the input string and aligning them in the position of characters present in the string.

Examples:

Input:
hello, world!

Output:
104101108108111443211911111410810033

Explanation:
h-104 e-101 l-108 l-108 o-111 ,-44  _-32 w-119 …… !-33

Input Format:
A string.

Constraint:

1 <= Length of the string <= 100

Output Format:
Equivalent ASCII sentence.

Sample Input 1

hello, world!

Sample Output 1

104101108108111443211911111410810033

Code:

#include<stdio.h>
#include<string.h>

int main()
{
    char a[100];
    fgets(a,100,stdin);
    for(int i=0;i<strlen(a)-1;i++)
    {
        if(a[i] == ' ') printf("32");
        else printf("%d",a[i]);
    }
    
}
Code language: C/AL (cal)

Leave a Comment