john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

file cat hex

/* John Pfeiffer 2010-06 display byte by byte values in console */

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
    FILE* fp;
    char c;     /* sizeof(char) always equals 1 byte */
    int i=0;


    if( 2 != argc )
    {    printf("wrong number of arguments, should be cat.exe filename\n");
        exit(1);
    }

    fp = fopen(argv[1],"rb");

    if( fp == NULL )
    {    printf("error opening file\n");    
    }
    else
    {
        c = getc(fp);
        while( !feof(fp) )
        {
            i++;
            printf("%x ", c );  /* cast a byte into unsigned int in hex */

            if( i % 8 == 0){    printf("\n");   }   /* readability */

            c = getc(fp);
        }

        fclose(fp);      
    }    
    return( 0 );
}/* end main */

  • « ups apc install checklist
  • Win CE create window main »

Published

Jun 30, 2010

Category

c

~79 words

Tags

  • c 95
  • cat 3
  • file 92
  • hex 3