I have actually this code for an embedded application. I am 1st trying to make it for plain c++ so that I may have concept clear
.
I have a digit code assigned to each English alphabet. I want that my program outputs equivalent digit code for a sentence. A loop actually should iterate number of times for each digit of the code for sentence. Bec I need to ON/OFF pins for me embedded application for each digit. I have to add time difference between digits of same letter, between two letters, & between two sentences later. 1st I wanted plain output for each digit of resultant code.
Here is my code. I have assigned alphabets to String & code to a String array type. Then I search for equivalent digit code of character from String array & save it in string type. Now I am wanting to assign each digit from string to int & loop for it. But I am having trouble in assigning string value to int. I have not much experience of C++ programming.
EDIT I have trouble in converting string to int at 1st place, & overall does this logic for solving my problem seems fine.
Here is my code, this is how I am trying to solve my 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 a single digit value from string to an
//int,string2int assign value is problem here !!
while(n>0){ //loop for n times & manipulate PIN in each iteration
cout<<"loop";
n--; }
//cout<<code[i]<<endl;
}
return 0;
}