Last active
August 29, 2015 14:05
-
-
Save narokwq/be8c4d955da31ce82487 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define BYTES 508 | |
#define TESR(i) isprint(val[i]) ? val[i] : '.' | |
unsigned long int Tamanho(FILE *con); | |
void getNome(char *local, char *nome); | |
int main(void) | |
{ | |
unsigned long int tam; | |
unsigned int ch = 1, val[10]; | |
int i, count = 0; | |
char caminho[100], nome[50]; | |
FILE *arquivo; | |
printf("Digite o caminho do arquivo\n"); | |
printf(">> "); | |
gets(caminho); | |
arquivo = fopen(caminho, "rb"); | |
if(arquivo == NULL){ | |
printf("O Arquivo nao pode ser aberto: %s", caminho); | |
exit(1); | |
} | |
getNome(caminho, nome); | |
printf("\nNome do arquivo: %s", nome); | |
if((tam = Tamanho(arquivo))) | |
printf("\nTamanho do arquivo: %ld Bytes\n\n", tam); | |
printf("Offset Bytes Caracteres\n"); | |
printf("------\t-----------------------------\t----------\n"); | |
printf("000000\t00 01 02 03 04 05 06 07 08 09\t \n\n"); | |
while(count < BYTES){ | |
printf("%6d\t", count); | |
for(i = 0; i < 10; i++){ | |
if((BYTES > count) && (ch = fgetc(arquivo)) != EOF){ | |
printf("%.2X ", ch); | |
val[i] = ch; | |
}else{ | |
printf(" "); | |
val[i] = ' '; | |
} | |
count++; | |
} | |
printf("\t"); | |
for(i = 0; i < 10; i++){ | |
printf("%c", TESR(i)); | |
} | |
printf("\n", count); | |
} | |
fclose(arquivo); | |
printf("\n\nSo lidos %d Bytes para teste.\n\n\n", BYTES); | |
system("pause"); | |
} | |
unsigned long int Tamanho(FILE *con){ | |
unsigned long int tamanho; | |
fseek(con, 0L, SEEK_END); | |
tamanho = ftell(con); | |
fseek(con, 0L, SEEK_SET); | |
return tamanho; | |
} | |
void getNome(char *local, char *nome){ | |
int i, j; | |
for(i=0, j=0; *(local+i) != '\0'; i++){ | |
if(*(local+i) == '/' || *(local+i) == '\\'){ | |
j = 0; | |
continue; | |
} | |
nome[j] = *(local+i); | |
j++; | |
} | |
nome[j] = '\0'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment