thx for the hint, i have it working printing hex (kinda, it messed up a little, like combines line 3 with line 1.. and prints out line 1 holding all the data) but trying to write hex doesnt work, it just simply doesnt write anything... here is my write and read code.
Oh and I just was testing around with keywords in C to see what happens. Is auto bad to use nowadays? I know it basically means 'local' variable, it can only be called in a function and that only that function its called in can use it.
Code:
void FileReadPrintHex(const char* FilePath) {
char line[200];
FILE *fp;
int z=0;
int count = 1;
if((fp = fopen(FilePath, "rb"))==NULL) { printf("%s does not exist!", FilePath);
} else {
printf("\n\nNow Opening: %s\n", FilePath);
while ( fgets(line, sizeof line, fp) != NULL)
{
printf("\nLine %i: ",count);
while(line[z]!='\n') {
printf(" %02x",line[z]);
z++;
}
count++;
}
fclose(fp);
}
}
void FileWriteHex(const char* FilePath, char line[200]) {
FILE *zp;
int z=0;
int count = 1;
if((zp = fopen(FilePath, "wb"))==NULL) { printf("%s does not exist!", FilePath);
} else {
printf("\n\nNow Opening: %s\n", FilePath);
while ( fgets(line, sizeof line, zp) != NULL)
{
while(line[z]!='\n') {
fprintf(zp,"%02x",line[z]);
printf("%02x",line[z]);
z++;
}
count++;
}
printf("DONE!");
fclose(zp);
}
}
Anything im doing wrong? it combines the hex together tinto line 1 (when printing, not writing). When writing, it doesnt write atall, it just formats the file to be written to.
Thx