View Single Post
Old Aug 28th, 2008, 10:47 AM   #15
mattireland
Hobbyist Programmer
 
mattireland's Avatar
 
Join Date: Jul 2007
Location: Wales, United Kingdom
Posts: 210
Rep Power: 2 mattireland is on a distinguished road
Send a message via MSN to mattireland Send a message via Skype™ to mattireland
Re: String to Char Array Conversion

Thanks for the reply. I've missed out a few of the irrelevant chunks but here's the bit that's concerned. It's a morse playing program:

void play (int cn, int pit)
{
  if (cn == 1)  { Beep(pit,66);  Sleep(40); Beep(pit,200); Sleep(80); }
  else if (cn == 2)  { Beep(pit,200); Sleep(40); Beep(pit,66); Sleep(40); Beep(pit,66); Sleep(40); Beep(pit,66); Sleep(80); }
  else if (cn == 3)  { Beep(pit,200); Sleep(40); Beep(pit,66); Sleep(40); Beep(pit,200); Sleep(40); Beep(pit,66); Sleep(80); }
  else if (cn == 11) { Beep(pit,200); Sleep(40); Beep(pit,66); Sleep(40); Beep(pit,200); Sleep(80); }
  else if (cn == 27) { Sleep(100); }
}

int main(int argc, char *argv[])
{    
    string s;
    int pitch;
    int i = 0, j = 0;
    cout << "Please enter a string: " ;
    cin >> s;
    cout << endl << "Please enter a pitch in Hz (recommended 750): ";
    cin >> pitch;
    j = s.length ();
    while (i < j) {
          if (s[i] == 'a')
             play(1, pitch);
          else if (s[i] == 'b')
             play(2, pitch);
          else if (s[i] == ' ')
             play(27, pitch);
          else
              cout << s[i];
    i++;
}

Thanks again.
__________________
Matt Ireland
http://www.mattireland.org
matt@mattireland.co.uk
mattireland is offline   Reply With Quote