So I have this code, and its giving me problems. In the first line of output, it displays how I want it to, after which it screws up. It's supposed to display 16 characters, then those 16 characters in hex. Oh by the way, I am using Linux.
Code:
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char** argv) {
int fd;
size_t linesize=16;
int i=0;
char buffer[4096];
ssize_t bytesRead;
ssize_t bytesPrinted=0;
char str[linesize+1];
int j;
fd=open(fd, O_RDONLY, 0);
while ((bytesRead = read(fd, buffer, 4096)) > 0){
for (i=0; i<bytesRead; i++) {
if (buffer[i]=='\0'){
exit(0);
}
else{
printf("%c ", buffer[i]);
str[i]=buffer[i];
bytesPrinted++;
begin++;
if (bytesPrinted % linesize == 0){
str[linesize]='\0';
for (j=0; j<linesize; j++){
printf("%2x ", str[j]);
}
str[0]='\0';
printf("\n");
}
}
}
}
return 0:
};
Oh by the way
sorry about misspelling and
my fingers got ahead of me.