
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C program to print the ASCII values in a string.
An array of characters is called a string.
Given below is the declaration of a string −
char stringname [size];
For example, char string[50]; string of length 50 characters.
Initialization
- Using single character constant.
char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}
- Using string constants.
char string[10] = “Hello”:;
Accessing
There is a control string “%s” used for accessing the string till it encounters ‘\0’.
The logic we used to print the ASCII values of a given string at runtime is as follows −
while(str[i]!='\0'){ printf("
ASCII Value of %c = %d", str[i], str[i]); i++; }
Example
Following is the C program to print the ASCII values of a given string −
#include<stdio.h> int main() { char string[50]; int i=0; printf("Enter the Sentenc: "); gets(string); while(string[i]!='\0') { printf("
ASCII Value of %c=%d", string[i], string[i]); i++; } getch(); return 0; }
Output
When the above program is executed, it produces the following output −
Enter the Sentence: Tutorials Point ASCII Value of T = 84 ASCII Value of u = 117 ASCII Value of t = 116 ASCII Value of o = 111 ASCII Value of r = 114 ASCII Value of i = 105 ASCII Value of a = 97 ASCII Value of l = 108 ASCII Value of s = 115 ASCII Value of = 32 ASCII Value of P = 80 ASCII Value of o = 111 ASCII Value of i = 105 ASCII Value of n = 110 ASCII Value of t = 116
- Related Articles
- C Program to print all ASCII values.
- Java Program to Print the ASCII values
- Swift Program to Print the ASCII values
- Kotlin Program to Print the ASCII values
- Haskell program to print ascii values
- Convert a string to hexadecimal ASCII values in C++
- How to print the ASCII values in Golang?
- Python program to find the sum of Characters ascii values in String List
- Count characters in a string whose ASCII values are prime in C++
- C++ program to print values in a specified format
- C program to print a string without any quote in the program
- Java program to print ASCII value of a particular character
- Program to find the largest and smallest ASCII valued characters in a string in C++
- Print shortest path to print a string on screen in C Program.
- C program to print string tokens

Advertisements