Tuesday, 29 October 2013

ASCII TO INTEGER PROGRAM IN C

#include //To obtain commands 

//CLEAR THE BUFFER SO PROGRAM DOES NOT END AFTER PRESSING ENTER 

void clearBuffer(void) 

 while(getchar()!='\n') 
{ } 

//CONVERTING ASCII TO INTEGER FUNCTION 

int asciiToInteger(int ascii) //Function to convert ASCII to decimal 


 ascii=ascii-0x30;  //Integer convertion by subtractin hex number return ascii; 



//********************************* MAIN FUNCTION**************************************** 

int main() 


//VARIABLES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
char key;
int character; 

//WHILE THE CONDITION IS MET REPEAT!!!!!!!!!!!!!!!! 

 while(key!='q') 


printf("Enter a character:\n"); 
character=asciiToInteger(getchar()); 
printf("\nThe integer representation of the character (%c - Ox%x) is %d\n",(character+30),(character+0x30),character); 

printf("Do you want to continue:\n"); 

printf("Press any key q to quit\n"); 

clearBuffer(); 
key=getchar(); 
clearBuffer(); 

return 0; 

} //Identifiers used to print hex and decimals

No comments:

Post a Comment