Skip to content

Commit

Permalink
Updated README.md and added html conversion features to ascii-tools.c
Browse files Browse the repository at this point in the history
  • Loading branch information
aliclubb committed May 18, 2012
1 parent d4b93b0 commit c8060c6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
6 changes: 5 additions & 1 deletion ascii-tools/README.md
Expand Up @@ -2,4 +2,8 @@ ascii-tools
==========

This is a collection of tools I am developing to deal with ASCII related conversion.
So far it does strings to ASCII values (-ascii) and ASCII values to strings (-char) :)
So far it does strings to ASCII values (-ascii) and ASCII values to strings (-char) :)

NOTE: The char to html function works for most characters, but breaks upon characters such as é
being entered. Also, html to ascii and html to char are currently not supported. I will add support
when I find the time.
38 changes: 31 additions & 7 deletions ascii-tools/ascii-tools.c
Expand Up @@ -3,25 +3,49 @@
#include <string.h>
int main (int argc, char const *argv[])
{
int i, c;
if(argc == 1)
printf("Usage: ascii-tools [options]\nOptions:\n-ascii\n-char\n");
else if(strcmp(argv[1], "-ascii") == 0)
printf("Usage: ascii-tools [inform] [outform]\nOptions:\nAny combination of the following:\n-ascii\n-char\n-html\n");
else if((strcmp(argv[1], "-char") == 0) && (strcmp(argv[2], "-ascii") == 0))
{
/* Small character to ASCII number converter */
/* Character to ASCII */
int c;
while ((c = getchar()) != EOF)
printf("%i ", c);
}
else if(strcmp(argv[1], "-char") == 0)
else if((strcmp(argv[1], "-ascii") == 0) && (strcmp(argv[2], "-char") == 0))
{
/* Small ASCII number to character converter */
/* ASCII to character */
int i;
char str[1];
while ((scanf("%s", str)) != EOF)
{
i = atoi(str);
putchar(i);
}
putchar('\n');
}
else if((strcmp(argv[1], "-char") == 0) && (strcmp(argv[2], "-html") == 0))
{
/* Character to html code */
int c;
while ((c = getchar()) != EOF)
{
if(c >= 9 && c <= 255)
{
printf("&#");
}
printf("%i ", c);
}
}
else if((strcmp(argv[1], "-ascii") == 0) && (strcmp(argv[2], "-html") == 0))
{
/* ASCII to html code */
int i;
char str[1];
while (scanf("%s", str))
{
i = atoi(str);
printf("&#%i ", i);
}
}
return 0;
}

0 comments on commit c8060c6

Please sign in to comment.