Email: bknpk@hotmail.com Phone: +972-54-7649119


V

 

Simple c++ exercise conversion of strings to hex values. The program is explained at: main page

  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. int main (int argc, char *argv[]) {
  6.   fstream infile;
  7.   string::size_type pos;
  8.   string st, sub_st;
  9.   unsigned int address, file_addr;
  10.   //std::stringstream ss;
  11.   if(argc != 2) {
  12.     cout << "Correct usuage:" << endl;
  13.     cout << "~/bin/cpp_fl_ini_TO_readmemh.out s25fl128p.ini" << endl;
  14.     cout << endl;
  15.     return 1;
  16.   }
  17.   //cout << "opening file " << argv[1] << endl;
  18.   infile.open (argv[1], ios::in);
  19.   if(infile.is_open()) {
  20.     address=0;
  21.     while(getline(infile,st)) {
  22.       pos = st.find('/');
  23.       sub_st=st.substr(0, pos);
  24.       sscanf(sub_st.c_str(), "%x", &file_addr);
  25.       cout << st << " " << sub_st << " " << file_addr << endl;
  26.     } //while
  27.   } else {
  28.     cout << "can not open " << argv[1] << endl;
  29.   }
  30.   infile.close();
  31.   return 0;
  32. } //main
  ...


Search This Site


Feedback This Site




new pages on this site