C++ alphabet equivalent digit code output program -


i have code embedded application. 1st trying make plain c++ may have concept clear.

i have digit code assigned each english alphabet. want program outputs equivalent digit code sentence. loop should iterate number of times each digit of code sentence. bec need on/off pins me embedded application each digit. have add time difference between digits of same letter, between 2 letters, & between 2 sentences later. 1st wanted plain output each digit of resultant code.

here code. have assigned alphabets string & code string array type. search equivalent digit code of character string array & save in string type. wanting assign each digit string int & loop it. having trouble in assigning string value int. have not experience of c++ programming.

edit have trouble in converting string int @ 1st place, & overall logic solving problem seems fine.

here code, how trying solve problem.

    #include <iostream>     #include <string>     using namespace std;           string texttopattern(char c)         {      //hello world again     //125-15-123-123-135 1346-135-1235-123-145 1-1245-1-24-1345          string alphabet = "abcdefghijklmnopqrstuvwqyz"; //osv         string code[] = {"1","12","14","145", "15", "124", "1245",                           "125", "24", "245", "13", "123", "134",                           "1345", "135", "1234", "12345", "1235", "234", "2345",                           "136", "1236", "1346", "13456", "1356", "12346"};           int index = alphabet.find(c);             if(index!=-1)                 return code[index];              else                 return " ";         }  int main() {     string ord;     getline(cin, ord);     string code="";         for(int i=0; i<ord.length(); i++)         {         code += texttopattern(ord[i]);         }          for(int i=0; i<code.length(); i++) {             int n = code[i]; //assign single digit value string                                 //int,string2int assign value problem here !!               while(n>0){    //loop n times & manipulate pin in each iteration                 cout<<"loop";                 n--;      }         //cout<<code[i]<<endl;         }          return 0; } 

i think should not use variable named int keyword in c++ , c.

so @ least have error on while loop. change while loop

       int j = code[i] - '0'; // number char         while(j>0){            cout<<"loop";            --j;              } 

Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -