PJF16

HexViewer

Dec 4th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4.  
  5. void showHex (char* file); //shows a file in hex code
  6.  
  7. int main (int argc, char* argv [])
  8. {
  9.     char filename [256];
  10.  
  11.     if (argc>1)
  12.     {
  13.         strcpy (filename, argv [1]);
  14.  
  15.     }
  16.     else
  17.     {
  18.         printf ("Dateiname: ");
  19.         fgets (filename, 255, stdin); //entspricht gets
  20.     }
  21.  
  22.     showHex (filename);
  23.  
  24.     return 0;
  25. }
  26.  
  27. void showHex (char *file)
  28. {
  29.     FILE *datei;
  30.     char text;
  31.  
  32.     datei = fopen (file, "r");
  33.  
  34.      if (datei != NULL)
  35.     {
  36.       while((text=getc(datei)) != EOF)
  37.       {
  38.         printf("%x", text);
  39.       }
  40.  
  41.      
  42.       fclose (datei);
  43.     }
  44.  
  45.  
  46.      else
  47.      {
  48.          fclose (datei);
  49.          printf ("Datei nicht gefunden!");
  50.          
  51.      }
  52.  
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment