Fandom

Scratchpad

PLE:Unidad6Ejercicio17

219,447pages on
this wiki
Add New Page
Discuss this page0 Share
/*
Programa:         Unidad6Ejercicio17.cpp
Descripción:      Visor hexadecimanl.
*/
#include <iomanip>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
using namespace std;

const int NUMBYTES = 128;

void visualiza(char b[], int n, long p);
char menu();

void main()
{
        int numBytes;
        char nomfich[80],opc;
        char buffer[NUMBYTES];
        ifstream fe;
        long pos;

        cout<<"Nombre de fichero: ";
        cin>>nomfich;

        fe.open(nomfich, ios::in | ios::binary);
        if(!fe.good())
        {
                exit(0);
        }
        else
        {
                while(opc != 's')
                {
                        // Leemos el buffer
                        fe.read(buffer,128);
                        numBytes = fe.gcount();
                        // Retrocedemos
                        if(numBytes == NUMBYTES)
                                    fe.seekg(-128, ios::cur);
                        else
                        {
                                    fe.clear();
                                    fe.seekg(0, ios::beg);
                        }
                        pos = fe.tellg();
                        // Visualizo
                        visualiza(buffer,numBytes, pos);
                        // Muestro el menu
                        opc = menu();
                        switch(opc)
                        {
                                case '+':       fe.seekg(128, ios::cur);
                                                break;
                                case '-':       fe.seekg(-128, ios::cur);
                                                break;
                        }
                }
                fe.close();
        }
}

void visualiza(char b[], int n, long p)
{
        int i, j;
        system("cls");
        cout << "Posicion actual es = " << dec << p << endl;
        cout << "Numero de bytes leidos = " << n << endl;
        cout << "Registro actual es = " << p/NUMBYTES << endl;
        for(i = 0; i < n; i++)
        {
                cout << hex << setfill('0') << setw(2) << (unsigned int) b[i+j] % 256 << ' ';
                if(i % 16 == 15)
                        cout << endl;
        }
}

char menu()
{
        char o;
        cout << endl << endl;
        cout << "********************** MENU **********************" << endl;
        cout << "(+) Siguiente Reg. (-) Anterior Registro (s) Salir" << endl;
        cin.get(o);
        return o;
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random wikia