Simple c++ exercise conversion of strings to hex values.
The program is explained at:
main page
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main (int argc, char *argv[]) {
- fstream infile;
- string::size_type pos;
- string st, sub_st;
- unsigned int address, file_addr;
- //std::stringstream ss;
- if(argc != 2) {
- cout << "Correct usuage:" << endl;
- cout << "~/bin/cpp_fl_ini_TO_readmemh.out s25fl128p.ini" << endl;
- cout << endl;
- return 1;
- }
- //cout << "opening file " << argv[1] << endl;
- infile.open (argv[1], ios::in);
- if(infile.is_open()) {
- address=0;
- while(getline(infile,st)) {
- pos = st.find('/');
- sub_st=st.substr(0, pos);
- sscanf(sub_st.c_str(), "%x", &file_addr);
- cout << st << " " << sub_st << " " << file_addr << endl;
- } //while
- } else {
- cout << "can not open " << argv[1] << endl;
- }
- infile.close();
- return 0;
- } //main
|