48 lines
1.3 KiB
Plaintext
48 lines
1.3 KiB
Plaintext
/* hex.c - Convert string from stdin to hex -> stdout
|
|
*
|
|
* Copyright 2000 Wilmer van der Gaast (lintux@lintux.cx)
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
// You know, I'm just a former QuickBASIC programmer... (I still am)
|
|
// Ah, who cares??? It works... No buffer overruns/etc. AFAIK...
|
|
|
|
#define byte_count 128 // Total number of lines of output
|
|
|
|
main ()
|
|
{
|
|
char str[byte_count];
|
|
int i, z;
|
|
|
|
z=0;
|
|
scanf ("%128c", &str);
|
|
for (i=0; i<byte_count; i++)
|
|
{
|
|
if (str[i]==37)
|
|
{
|
|
printf ("%c%c\n", str[i+1], str[i+2]);
|
|
i+=2;
|
|
z+=2;
|
|
}
|
|
else if (str[i]>=32)
|
|
printf ("%2X\n", str[i]);
|
|
else
|
|
printf ("00\n", str[i]);
|
|
}
|
|
for (i=0; i!=z; i++)
|
|
printf("00\n");
|
|
}
|