summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2010-11-08 11:09:57 +0000
committerIan C <ianc@noddybox.co.uk>2010-11-08 11:09:57 +0000
commit0657049c03daec5ff88043f12d0f6ce6534942bb (patch)
tree9a2f0eca88dca3497c81377a0340acacc40578c7
parent604905dc5e105d3a08f2eef51cd30761b7941242 (diff)
Tidied up hex.c
-rw-r--r--hex.c65
1 files changed, 41 insertions, 24 deletions
diff --git a/hex.c b/hex.c
index 1323756..39076be 100644
--- a/hex.c
+++ b/hex.c
@@ -1,29 +1,10 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <ctype.h>
-int main(int argc,char *argv[])
-
-{
- void Dump(char *fn,FILE *fp);
- FILE *fp;
- int f;
-
- if (argc==1)
- Dump("stdin",stdin);
- else
- for(f=1;f<argc;f++)
- if ((fp=fopen(argv[f],"r")))
- {
- Dump(argv[f],fp);
- fclose(fp);
- }
- else
- fprintf(stderr,"Couldn't open %s\n",argv[f]);
-}
-
-void Dump(char *fn,FILE *fp)
+static void Dump(char *fn,FILE *fp)
{
char s[17];
int p;
@@ -36,27 +17,63 @@ void Dump(char *fn,FILE *fp)
p=0;
while(b!=EOF)
- {
+ {
strcpy(s," ");
printf("%6.6x: ",p);
p+=16;
for(f=0;f<16;f++)
- {
+ {
if((b!=EOF)&&((b=getc(fp))!=EOF))
- {
+ {
printf("%2.2x ",(unsigned char)b);
if (isprint(b))
+ {
s[f]=b;
+ }
else
+ {
s[f]='.';
}
+ }
else
+ {
printf("** ");
}
+ }
printf(" %s\n",s);
+ }
+}
+
+int main(int argc,char *argv[])
+{
+ FILE *fp;
+ int f;
+ int ret = EXIT_SUCCESS;
+
+ if (argc==1)
+ {
+ Dump("stdin",stdin);
+ }
+ else
+ {
+ for(f=1;f<argc;f++)
+ {
+ if ((fp=fopen(argv[f],"r")))
+ {
+ Dump(argv[f],fp);
+ fclose(fp);
+ }
+ else
+ {
+ fprintf(stderr,"Couldn't open %s\n",argv[f]);
+ ret = EXIT_FAILURE;
+ }
}
+ }
+
+ return ret;
}