Hi All,
First up, i am going to tell you that i am not a full-time programmer - i design digital circuits. However i have tinkered with cpp for different tasks. I need for a current project to take a file containing ascii characters - hex values that i need to read, line by line and store in an array of integers so that i can post-process them. The file contents look like the following;
ABCD
FFDE
1234
etc - i want to read these in and convert them to 16-bit integer numbers.
I have tried the following.
Code:
int main(int argc, char **argv) {
long memVal[256*8];
int lineNum=0;
FILE *hexFile;
hexFile = fopen("ppmem.hex","r");
if(hexFile != NULL) {
cout << "ppmem.hex successfully opened for read" << endl;
while(!feof(hexFile)){
fscanf(hexFile, "%x", &memVal[lineNum]);
//lineNum < 5 ? lineNum +=5 : lineNum += 4;
cout << memVal[lineNum] << endl;
lineNum ++;
}
cout << "Total number of lines read: " << lineNum << endl;
return 0;
}else{
cout << "Error opening ppmem.hex" << endl;
return -1;
}
}
I must be missing something somewhere, the output is
ppmem.hex successfully opened for read
lineNum 0 -> 0
lineNum 1 -> 0
lineNum 2 -> 0
lineNum 3 -> 0
lineNum 4 -> 0
lineNum 5 -> 0
lineNum 6 -> 0
...
Total number of lines read: 50
I would also like to have the loop not require me to enter the number of line - but one problem at a time. Thanks for looking - and sorry for my ignorance.