How do you implement a good profanity filter?

Obscenity Filters: Bad Idea, or Incredibly Intercoursing Bad Idea? Also, one can’t forget The Untold History of Toontown’s SpeedChat, where even using a “safe-word whitelist” resulted in a 14-year-old quickly circumventing it with: “I want to stick my long-necked Giraffe up your fluffy white bunny.” Bottom line: Ultimately, for any system that you implement, there … Read more

Why does my string not match when reading user input from stdin?

Instead of trim_end_matches (previously called trim_right_matches), I’d recommend using trim_end (previously called trim_right) or even better, just trim: use std::io; fn main() { let mut correct_name = String::new(); io::stdin() .read_line(&mut correct_name) .expect(“Failed to read line”); let correct_name = correct_name.trim(); if correct_name == “y” { println!(“matched y!”); } else if correct_name == “n” { println!(“matched n!”); … Read more

Disadvantages of scanf

Most of the answers so far seem to focus on the string buffer overflow issue. In reality, the format specifiers that can be used with scanf functions support explicit field width setting, which limit the maximum size of the input and prevent buffer overflow. This renders the popular accusations of string-buffer overflow dangers present in … Read more

std::cin input with spaces?

It doesn’t “fail”; it just stops reading. It sees a lexical token as a “string”. Use std::getline: #include <string> #include <iostream> int main() { std::string name, title; std::cout << “Enter your name: “; std::getline(std::cin, name); std::cout << “Enter your favourite movie: “; std::getline(std::cin, title); std::cout << name << “‘s favourite movie is ” << title; … Read more

user input errors illegal start of expression and type

Edit: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; class Question { public static void main(String[] args) { try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String input = in.readLine(); if (“you’re my daddy.”.equals(input)) { System.out.println(“correct”); } else { System.out.println(“try again”); } } catch (IOException ex) { System.out.println(“Error reading from System.in”); } } } Another hint for … Read more

C++ Creating a parking charge

Your are almost done, You have need to call functions properly in main function. Declare two variables in main function totalTime and totalChargethen call the function #include <iostream> using namespace std; int elapsed_time(int entry_time, int exit_time) { int total = 0; total = (exit_time / 100) * 60 + (exit_time % 100) – (entry_time / … Read more

How to shift characters to ASCII values in a file based on user input c++ [closed]

A simple implementation of the Caesar Cipher is to use a string of valid characters and the remainder operator, %. char Encrypt_Via_Caesar_Cipher(char letter, unsigned int shift) { static const std::string vocabulary = “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ”; const std::string::size_type position = vocabulary.find(letter); char c = letter; if (position != std::string::npos) { const std::string::size_type length = vocabulary.length(); c = vocabulary[(position … Read more

HOW to back for the beginning if the user press any key except 1 or 2 or 3? [closed]

Use do–while loop and set the condition to while(L != ‘1’ && L != ‘2’ && L != ‘3’);: do { L = getch(); switch (L) { case ‘1’ : system(“cls”); printf(“111111111111111”); break; case ‘2’ : system(“cls”); printf(“222222222222222”); break; case ‘3’ : system(“cls”); printf(“33333333”); break; default : sleep(0); } } while(L != ‘1’ && L … Read more