Character to ASCII in C

Aadesh
@aadesh-FqoMCL โ€ข Oct 25, 2024

How do i convert character to ascii value and then perform arithmetic operations on the ascii values and get the character of the ascci value? in c programming !
help asap

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Aadesh

    @aadesh-FqoMCL • Jun 21, 2012

    get the character of the *new* ascii value

  • Neeraj Sharma

    @neeraj-iAaNcG • Jun 21, 2012

    Its all about format specifiers. Normally for printing a character, you use %c but instead of %c, if you use %d for character, it gives you the ascii value. For adding, add both the characters and store the result in integer variable, so that the ascii values are added. Following program will give a clear idea about it.

    #include<stdio.h>
    int main()
    {
      char ch1='a',ch2='b';
      int add;
      printf("Ascii value of %c: %d",ch1,ch1);
      printf("Ascii value of %c: %d",ch2,ch2);
      add=ch1+ch2;
      printf("Character for Ascii value %d: %c",add,add);
      return 0;
    }