C Program to find ASCII Value of All Characters in a String

In this tutorial, i am going to show you how to find the ascii value of all characters in a given string with the help of for loop and while loop.

All C Programs to find ASCII Value of All Characters in a String

  • 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 result 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 result 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 

More C Programming Tutorials

Leave a Comment