user-input

Dynamically allocate user inputted string

末鹿安然 提交于 2019-12-17 14:58:08
问题 I am trying to write a function that does the following things: Start an input loop, printing '> ' each iteration. Take whatever the user enters (unknown length) and read it into a character array, dynamically allocating the size of the array if necessary. The user-entered line will end at a newline character. Add a null byte, '\0' , to the end of the character array. Loop terminates when the user enters a blank line: '\n' This is what I've currently written: void input_loop(){ char *str =

How to Test Character Input to UITextField as the User Enters Characters and Prevent Invalid Characters

半世苍凉 提交于 2019-12-17 10:29:40
问题 First, I setup up the keyboard for the UITextField to use the number with decimal style. So the user can only enter numbers and a single decimal. What I want to do is test the input as the user enters it and prevent multiple decimals from being entered and limit the decimal portion of the number to two places. I do not want to round off the number nor even treat the input as a number. I simply want to prevent the user from entering more then two digits to the right of the decimal place. 回答1:

Hide input on command line

家住魔仙堡 提交于 2019-12-17 04:59:15
问题 I know that command line interfaces like Git and others are able to hide input from a user (useful for passwords). Is there a way to programmtically do this in Java? I'm taking password input from a user and I would like their input to be "hidden" on that particular line (but not on all of them). Here's my code for it (though I doubt it would be helpful...) try (Scanner input = new Scanner(System.in)) { //I'm guessing it'd probably be some property you set on the scanner or System.in right

How to show “Done” button on iPhone number pad

放肆的年华 提交于 2019-12-16 22:20:55
问题 There is no "Done" button on the number pad. When a user finishes entering numeric information in a text field, how can I make the number pad disappear? I could get a "Done" button by using the default keyboard, but then users would have to switch to the numeric keys in order to input numbers. Is there a way to show a "Done" button on the number pad? 回答1: Another solution. Perfect if there are other non-number pad text fields on the screen. - (void)viewDidLoad { [super viewDidLoad]; UIToolbar

How to sum any amount of user inputted numbers from a single line

自古美人都是妖i 提交于 2019-12-14 03:02:40
问题 Trying to figure out how I would take any amount of inputted numbers from a user and add them together Example user input: 1 2 3 4 Sum = 10 The user can put any amount of numbers in not a specified amount so if he wanted to add 1 2 3 4 5 6 7 8 9 10 11 12 13, it would sum them all up to 91 Thanks for the help in advance. import java.util.Scanner; public class test { public static final int SENTINEL = -1; public static void main(String[] args) { Scanner kb = new Scanner(System.in); int score =

Python | Skipping a user_input

会有一股神秘感。 提交于 2019-12-13 23:37:45
问题 I have a problem with my python script as when this question comes up: ("Is there problem with the software or hardware? ") When I type in "Software" my first software question comes up ("Is your phone freezing/stuttering? ") So if I answer yes a solution comes up b``ut if I type in No then my hardware question comes up but I dont want that to happen. Here is my script: phone2 = input("Is there problem with the software or hardware? ") #Question if phone2 == "Software" or phone2 == "software"

i cant get my calculator to work

妖精的绣舞 提交于 2019-12-13 22:50:16
问题 i want to input a int to get first number then use a string to get the operator and another int for the second number. user should input some thing like 10+20. but as soon as i enter the "+" then i get an error why? cuz it works if i manually add the values into the sum.calc(); myself like sum.calc(12, "+", 24); then it works ill get 36 PART 1: import java.util.Scanner; public static void main(String[] args) { math sum = new math(); Scanner input = new Scanner(System.in); double a = input

Batch File: Getting user input during execution of other commands, then checking it later

僤鯓⒐⒋嵵緔 提交于 2019-12-13 19:57:20
问题 What I want is a command (or series of commands) that works with Windows 7, 8.1, and 10. It needs to collect user input at any time during the execution of the batch file it's in, only to checked and interpreted later. I do not mind using an input text file. I've already searched for an answer, but the closest I've come to it is <nul set /p "input=" , but it requires the user to press a key and hit enter at the exact moment the command is run. Any help would be greatly appreciated. 回答1: This

C Programming: Initialize a 2D array of with numbers 1, 2, 3…etc

北慕城南 提交于 2019-12-13 08:56:19
问题 I am having trouble creating a 2D Array of a size defined by the user, with numbers 1, 2, 3.etc. If the user chooses for example: a = 2 and b = 2 , the program produces: 3 4 3 4 instead of: 1 2 3 4 My program looks like: #include <stdio.h> int main() { int a = 0; int b = 0; int Array[a][b]; int row, column; int count = 1; /*User Input */ printf("enter a and b \n"); scanf("%d %d", &a, &b); /* Create Array */ for(row = 0; row < a; row++) { for(column = 0; column <b; column++) { Array[row]

How to read only digits from input (no letters, just digits) in C?

你离开我真会死。 提交于 2019-12-13 08:30:06
问题 You helped me a while ago with reading a line. Now, I want to read only digits from input - no letters, just 5 digits. How can I do this? My solution doesn't work properly: int i = 0; while(!go) { printf("Give 5 digits: \n\n"); while( ( c = getchar()) != EOF && c != '\n' && i < 5 ) { int digit = c - '0'; if(digit >= 0 && digit <= 9) { input[i++] = digit; if(i == 5) { break; go = true; } } } } 回答1: With the break statement, go = true; will never be executed. Therefore the loop while (!go) is