Advertisement
Guest User

Untitled

a guest
Nov 4th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. const char *compare_string(int type=1) {
  2. switch (type)
  3. {
  4. case(1):
  5. return "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM ";
  6. case(2):
  7. return " qwertyuiopasdfghjklzxcvbnm,.?!-@QWERTYUIOPASDFGHJKLZXCVBNM ";
  8. case(3):
  9. return " qwertyuiopasdfghjklzxcvbnm,.?!-@QWERTYUIOPASDFGHJKLZXCVBNM 1234567890";
  10. }
  11. }
  12.  
  13. bool check_string(const char *S, int typet=1) {
  14. if (typet < 4) {
  15. const char *temp = compare_string(typet);
  16. unsigned point_count = 0;
  17.  
  18. for (int i = 0; i < strlen(S); i++) {
  19. if (!strchr(temp, S[i]))
  20. //return check_string(S, typet+1);
  21. return false;
  22. }
  23. return true;
  24. }
  25. //else {
  26. // return false;
  27. //}
  28. }
  29.  
  30. char *getstring() {
  31. const int N = 1000;
  32. char S[N];
  33. if (cin.peek() == '\n') cin.ignore(100, '\n');
  34. cin.getline(S, N);
  35. bool inpOk = false;
  36. while (!inpOk) {
  37. if (!check_string(S)) {
  38. cerr << "Invalid input. Try again." << endl;
  39. cin.getline(S, N);
  40. }
  41. else
  42. inpOk = true;
  43. }
  44. return S;
  45. }
  46. int main(){
  47. //setlocale(LC_ALL, "");
  48. char *s = getstring();
  49. printf("%s", &s);
  50. return 0;
  51. }
  52. //input CPP
  53. //output o'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement