This is a C Program to input a string & store their Ascii Values in an Array & print the Array
Problem Description
This program will take an input of string & store their ASCII values and print them.
Problem Solution
1. Create an array of characters and take its size from users as an input.
2. Enter a string.
3. Using a loop, scan each element(character) of the string and print its equivalent ASCII value, increment the value of iterator used to access the position of characters of the string.
Program/Source Code
Here is source code of the C Program to input a string & store their ascii values and print them. The program is successfully compiled and tested using Turbo C compiler in windows environment. The program output is also shown below.
/*
* C Program to Input a String & Store their Ascii Values in an Integer Array & Print the Array
*/
#include
void main()
{
char string[20];
int n, count = 0;
printf(“Enter the no of characters present in an array \n “);
scanf(“%d”, &n);
printf(” Enter the string of %d characters \n” , n);
scanf(“%s”, string);
while (count < n) { printf(" %c = %d\n", string[count], string[count] ); ++ count ; } } Runtime Test Cases Enter the no of characters present in an array 10 Enter the string of 10 characters sanfoundry s = 115 a = 97 n = 110 f = 102 o = 111 u = 117 n = 110 d = 100 r = 114 y = 121