Code:
#include<stdio.h>
#include<stdlib.h>
#include<sys/ioctl.h>
int main(int argc,char** argv)
{
struct winsize terminal;
FILE* fp;
int a, c, column, row, lines;
ioctl(0, TIOCGWINSZ,&terminal, argv[2]);
fp = fopen(argv[1],"r");//set open for argv[1] and set it to read mode
column = terminal.ws_col;
row = terminal.ws_row;
lines = atoi(argv[2]);
// printf("Rows are: %d\n", row);
// printf("Columns are: %d\n", column);
if(argc <3)//Argument checking, at least three to run
{
printf("You need atleast 3 arguments to run!\n");
exit(1);
}
if(fp == NULL)
{
fprintf(stderr,"Error opening '%s'.\n", argv[1]);//if not file is specified then close program and give an error
exit(1);
}
c = fgetc(fp);//set c to fgetc
if(column <80|| row <20)//if temrinal window is less than 80x20, display an error and exit
{
printf("Terminal window must be at least 80x20!\n");//display error and close program if column criteria isn't met
exit(1);
}
/*
while(!feof(fp)) //if file is entered, display a test message (this is where later on I will show hex value)
{
printf("Good Job! You picked a file to manipulate!!\n");
exit(1);
}
*/
if(lines ==0)//if 0 is entered for argv[2], display all the lines, 512 byte file
{
printf("------------------------------------------------------------------------------\n");//**this is where I try to display character/hex banner**
printf("offset 0 1 2 3 4 5 6 7 8 9 a b c d e f ascii\n");
printf("-------------------------------------------------------------------------------\n");
printf("0x%08x\n" , c);
}
elseif(lines ==20)
{
printf("This will print out 20 lines\n");
}
elseif(lines ==30)
{
printf("This will print out 30 lines\n");
}
else
{
printf("Please Enter a Valid Number!\n");
}
fclose(fp);//close fp
return0;
}
This is my current code with an output of
Code:
~//cbf0$ ./cbf0 win7.mbr 0
------------------------------------------------------------------------------
offset 0 1 2 3 4 5 6 7 8 9 a b c d e f ascii
-------------------------------------------------------------------------------
0x00000033
and my desired output would be:
Code:
l~/cbf0$ ./cbf0 win7.mbr 0
------------------------------------------------------------------------------
offset 0 1 2 3 4 5 6 7 8 9 a b c d e f ascii
-------------------------------------------------------------------------------
0x00000000
0x00000010
0x00000020
0x00000030
0x00000040
0x00000050
0x00000060
0x00000070
0x00000080
0x00000090
0x000000a0
"and so on.."