C program to find the ascii value of all characters in a string; Through this tutorial, we will learn how to find the ascii value of all characters in a given string using for loop and while loop.
Programs to find ASCII Value of All Characters in a String in C
- C Program to find ASCII Value of All Characters in a String using for loop
- C Program to find ASCII Value of All Characters in a String using while loop
C Program to find ASCII Value of All Characters in a String using for loop
/* C Program to find ASCII Value of Total Characters in a String */ #include <stdio.h> int main() { char str[100]; printf("\n Please Enter any String : "); scanf("%s", str); for( int i = 0; str[i] != '\0'; i++) { printf(" The ASCII Value of Character %c = %d \n", str[i], str[i]); } return 0; }
The output of the above c program; as follows:
Please Enter any String : tutsmake The ASCII Value of Character t = 116 The ASCII Value of Character u = 117 The ASCII Value of Character t = 116 The ASCII Value of Character s = 115 The ASCII Value of Character m = 109 The ASCII Value of Character a = 97 The ASCII Value of Character k = 107 The ASCII Value of Character e = 101
C Program to find ASCII Value of All Characters in a String using while loop
/* C Program to find ASCII Values of Total Characters in a String */ #include <stdio.h> int main() { char str[100]; int i = 0; printf("\n Please Enter any String : "); scanf("%s", str); while( str[i] != '\0') { printf(" The ASCII Value of Character %c = %d \n", str[i], str[i]); i++; } return 0; }
The output of the above c program; as follows:
Please Enter any String : tutsmake The ASCII Value of Character t = 116 The ASCII Value of Character u = 117 The ASCII Value of Character t = 116 The ASCII Value of Character s = 115 The ASCII Value of Character m = 109 The ASCII Value of Character a = 97 The ASCII Value of Character k = 107 The ASCII Value of Character e = 101