C program to get the ascii string from a string
2012-07-25
175 words
1 min read
Lot of times, you would like to get the complete string in hex or ascii format and if you are one of them then this is something that will be helpful for you 🙂
Example output:
lp-amita[d=~/bin]> ./ascii aamit
String – aamit, Length – 5String : aamit
Hex : 0x61616d6974
Dec : 9797109105116
And the source code:
/*n* ===================================================================================== * * Filename: ascii.c * * Description: ascii to dec * * Version: 1.0 * Created: 03/02/2012 12:08:49 PM * Revision: none * Compiler: gcc * * Author: Amit Agarwal (aka) * Last modified: Thu Mar 08, 2012 08:47PM * * ===================================================================================== */ void main (int argc, char **argv){ int i=0; char a[200]="",b[200]=""; printf("String - %s, Length - %dn",argv[1],strlen(argv[1])); while (i < strlen(argv[1])){ sprintf(a,"%s%x",a,argv[1][i]); sprintf(b,"%s%d",b,argv[1][i]); i++; } printf ("n"); printf ("String : %sn",argv[1]); printf ("Hex : 0x%sn", a); printf ("Dec : %sn", b); }
Related articles
Related Articles:
- 2012/04/13 Convert string to hex.
- 2012/05/07 Array of all possible colors in bash script
- 2011/11/28 Linux hardware details.
- 2010/04/11 core dump checking script.
- 2010/04/03 10 Keyboard Techniques To Create Cool Symbols
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.