Introduction
In C programming, ASCII values are used to represent characters as integers. Converting a string to ASCII values can be useful in various applications like encryption, data processing, and sorting algorithms. This article will guide you on how to convert a string to its corresponding ASCII values in C.
The ASCII Table
Before we delve into the code, let’s take a quick look at the ASCII table. The ASCII table maps each character to a unique integer value from 0 to 255. This mapping allows us to convert characters to their respective ASCII values and vice versa.
The Approach
To convert a string to ASCII values in C, we can iterate through each character of the string and use the `int` data type to store the ASCII value. Here’s the step-by-step process:
Step 1:
Take input from the user as a string.
Step 2:
Iterate through each character of the string.
Step 3:
Use the `int` data type to store the ASCII value of each character.
Step 4:
Display the ASCII values.
Example Program
“`c
#include
int main() {
char str[100];
printf(“Enter a string: “);
scanf(“%s”, str);
int i = 0;
while(str[i] != ‘