using <ctrl>-Z to end

Oct 15, 2009 at 7:26pm
hi, im trying to write a program to take in a bunch of information and then convert it accordingly. My only real problem is that we are asked to end the program once the user enters <ctrl>-Z. I think im supose to be using some kind
of signal or something. Help is much appreciated. Heres my code so far. The last if statement in main is where im having troubles


#include <iostream>
#include <iomanip>

char reverseCaesar(char ch);
char convPunct(char ch);
char convDigit(char ch);
char convRest (char ch);

using namespace std;

//*****************************************************


int main()
{
char ch;
cin >> ch;
while ( cin )
{
if (isdigit(ch))
{
ch = convDigit (ch);
}
if (ispunct(ch))
{
ch = convPunct (ch);
}
if (isalpha(ch))
{
ch = reverseCaesar (ch);
}
if (!isdigit(ch) || !ispunct(ch) || !isalpha(ch))
{
ch = convRest (ch);
}
if (ch == <ctrl>-Z)
{
break;
}
cout << ch;
cin>> ch;
}
}
}
//*****************************************************

char reverseCaesar(char ch)
{
char ch;
if (ch > 88)
{
ch = ch - 23;
return ch;
}
else
{
ch = ch + 3;
return ch;
}

//*****************************************************

char convPunct(char ch)
{
char ch;
switch ch
{
case '!'
ch = 0;
break

case ','
ch = 1;
break

case ')'
ch = 2;
break

case '('
ch = 3;
break

case '?'
ch = 4;
break

case '-'
ch = 5;
break

case '&'
ch = 6;
break

case '$'
ch = 7;
break

case '.'
ch = 8;
break

case '+'
ch = 9;
break
}
return ch;
}

//****************************************************

char convDigit(char ch)
{
char ch;
switch ch
{
case '0'
ch = ,;
break

case '1'
ch = .;
break

case '2'
ch = $;
break

case '3'
ch = &;
break

case '4'
ch = %;
break

case '5'
ch = *;
break

case '6'
ch = (;
break

case '7'
ch = );
break

case '8'
ch = ?;
break

case '9'
ch = !;
break
}
return ch;
}

//**********************************************************

char convRest(char ch)
{
char ch;
if (ch = 22)
{
return ;
}
if (ch = 21)
{
return /n;
}
}

Oct 15, 2009 at 7:51pm
ch = &;
Have you tried actually compiling this? There are no single quotes around anything!

About your question: http://www.cplusplus.com/reference/clibrary/csignal/signal/
You'll need SIGINT, I think.
Oct 15, 2009 at 8:04pm
im told i need to use SIGSTP using a trap but i dont know what that looks like in code
Oct 15, 2009 at 8:26pm
See the example at the bottom of the article.
Topic archived. No new replies allowed.