Hello,
I have a text file that contains lines that look like this:
FDB $01F0
I want to take the first three numbers after the "$" and convert them to decimal. I would like to output them into a new file or just display them, it doesn't matter. I found this to start:
Firstly, write a function that takes a hex digit '0', '1' , '2' ... 'E', 'F' and converts it to integer numbers 0, 1, 2 ... 14, 15. Then apply this function to every digit.
How conversion works:
F -> 15*1 = 15
C7 -> 12*16+7*1 = 199
12B -> 1*256+2*16+11 = 299
decimal number is the sum of every digit multiplied by 16pusition of that number
when I replace it with Table (My file name) I get an undeclared identifier error. When I replace it with "Table" I get this:
'fgets' : cannot convert parameter 3 from 'const char [6]' to 'FILE *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
#include "stdio.h"
int main(){
int i;
char s[100];
FILE * f=fopen("Table.txt","r");//replace table.txt with the name of your file.
while(fgets(s,100,f)){
if(sscanf(s,"%*[^$]$%3x",&i)>0){
printf("%d\n",i);
}
}
fclose(f);
}
You mean replace them? Try opening another file, writing the new data in, deleting the old one, and renaming the new one to the name of the old one. The easiest way to do the rename and delete is to use system() to use whatever commands your computer has for that.
I dunno if those work on files in another folder... stdio.h makes no reference to the concept of directories, although I admit it would be weird if it didn't work.
Uhhuh? Congrats you turned line 8 and and half of line 7 of my solution into 3 lines and an extra object!
And what about getting the 3 digits from after the '$'?
I don't think there's a simple equivalent to "%*[^$]$%3x", especially the first part.
Remember that my solution only does the printing if the entire format matches!
Bah, stupid sstream bullsh!t elitism.
And if the number of characters before the dollar sign varied?
And if some lines didn't have a dollar sign?
Your solution will no doubt involve ignore(), an if statement to check for EOL versus finding the dollar sign, and other manual format matching that tries desperately to match the functionality of the superior scanf interface.
What are these nice benefits?