This is a C Program to input a string & store their Ascii Values in an Array & print the Array
This program will take an input of string & store their ASCII values and print them.
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.
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
int n, count = 0;
printf("Enter the no of characters present in an array \n ");
printf(" Enter the string of %d characters \n" , n);
while (count < n)
printf(" %c = %d\n", string[count], string[count] );
++ count ;
1. Declare an array of characters of some fixed size, 20.
2. Take size from users as an input.
3. Now, enter a string again as an input, store it in character array declared above.
4. Run a for loop, which will scan each array element (i.e character), printing its equivalent ASCII code using %d notation and the character itself using %c inside printf() function.
5. Increment iterator, count after printf() statement to access next position.
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
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Books in C Programming, Data Structures and Algorithms.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Practice BCA MCQs
- Watch Advanced C Programming Videos
- Apply for C Internship
- Apply for Computer Science Internship
- Practice Computer Science MCQs