stdin

Eclipse reading stdin (System.in) from a file

馋奶兔 提交于 2019-12-27 12:17:10
问题 Is it possible for Eclipse to read stdin from a file? 回答1: Pure Java You can redirect System.in with a single line of code: System.setIn(new FileInputStream(filename)); See System.setIn(). Eclipse config In Eclipse 4.5 or later, the launch configuration dialog can set System.in to read from a file. See the announcement here. 回答2: [Update] As it has been pointed out in the comments, this answer was misleading so I have updated it to correct the errors. [/Update] On bash or command prompt you

How to read string from stdin until meet blank lines

岁酱吖の 提交于 2019-12-25 18:29:19
问题 Consider a simple program. It must take string from stdin and save to variable. It is not stated how many lines of input will be taken, but program must terminate if meet newline. For example: stdin: abc abs aksn sjja \n I tried but it doesn't work. Here is my code: #include <iostream> #include <cstring> #include <cstdio> using namespace std; // Constant #define max 100000 struct chuoi { char word[10]; }; chuoi a[max]; void readStr() { int i=0; while ( fgets(a[i].word, 10,stdin) != NULL) { if

How to read string from stdin until meet blank lines

对着背影说爱祢 提交于 2019-12-25 18:29:07
问题 Consider a simple program. It must take string from stdin and save to variable. It is not stated how many lines of input will be taken, but program must terminate if meet newline. For example: stdin: abc abs aksn sjja \n I tried but it doesn't work. Here is my code: #include <iostream> #include <cstring> #include <cstdio> using namespace std; // Constant #define max 100000 struct chuoi { char word[10]; }; chuoi a[max]; void readStr() { int i=0; while ( fgets(a[i].word, 10,stdin) != NULL) { if

Writing a C program that ignores the order of operations?

冷暖自知 提交于 2019-12-25 17:47:42
问题 I want to write a C program that takes a simple math problem from the user and use different processes to solve each part, and then send the value back to the parent process. This program should not pay attention to the order of operations. For instance, if I have the problem: 3 + 4 / 7 + 4 * 2 I want my program to output the following: Enter problem: 3 + 4 / 7 + 4 * 2 PID 20419 calculated 3+4 as 7 PID 20420 calculated 7/7 as 1 PID 20421 calculated 1+4 as 5 PID 20422 calculated 5*2 as 10

In the mac terminal - how can I get arrow keystrokes from stdin?

江枫思渺然 提交于 2019-12-25 07:49:40
问题 I'd like to browse a terminal dialog menu with the arrow keys (like bash 'dialog') I would prefer ruby solution, but bash/python could work. read -n1 input # is not good enough, cause the arrow keys are not regular chars. Also, the 'read' in mac term doesn't support smaller timeout than 1 second. Anything? Thanks, 回答1: I am not sure what you are looking for - a way to simulate key presses to an application, or a way to generate simple dialog boxes, or a way to read characters from a keyboard.

Linux Redirection to C program - File Reading

孤人 提交于 2019-12-25 07:48:33
问题 I want to read lines of numbers from the text file ( filename.txt ) using a function in C. How do I open this file (provided the filename is only given through a redirection on Unix)? i.e. ./cfile < filename.txt int main (void) { char filename[20]; fgets(filename, 19, stdin); FILE *fp; fp = fopen(filename, "r"); } So, would this be correct; also, how do I access one line at a time from the file (all I know is EOF has to be used somewhere)? 回答1: The contents of filename.txt gets redirected to

How to use select to read input from stdin?

别说谁变了你拦得住时间么 提交于 2019-12-25 07:04:59
问题 I am trying to read from stdin using select , after that I am sending the data through a socket to a server. The following snippet is supposed to follow the above logic; but it doesn't read anything from stdin . Moreover it prints Enter command: after the first time the user inputs a string. The line printf("%d %s\n",__LINE__ ,buf); doesn't print anything as either. fd_set rfds; struct timeval tv; int retval; char buf[BUFLEN]; while(1) { FD_ZERO(&rfds); FD_SET(STDIN_FILENO, &rfds); tv.tv_sec

date format dd.mm.yyyy in C

荒凉一梦 提交于 2019-12-25 04:09:04
问题 I want to know if there is a way to read date from console in format dd.mm.yyyy in C. I have a structure with information for the date. I tried with another structure just for the date with day, month and year in it: typedef struct { int day; int month; int year; } Date; but the dots are a problem. Any idea? 回答1: Try: Date d; if (scanf("%d.%d.%d", &d.day, &d.month, &d.year) != 3) error(); 回答2: You can use strptime() to read in an arbitrary formatted date string into a struct tm . #define

How to compare input from process.stdin to string in NodeJS?

一笑奈何 提交于 2019-12-25 03:36:11
问题 I'm using nodeJS and I want to be able to pass it commands via stdin. To do this I'm using process.stdin. Ideally I'd have a giant switch with various command strings like "load" or "stop", but I can't get the comparison to work. I've tried slicing out newlines, converting to strings, etc. Can't figure this out, though it seems like it should be fairly simple. Below is the code I've been trying to get to work: process.stdin.setEncoding('utf8'); process.stdin.on('readable', function() { var

Receiving binary data from stdin, sending to channel in Go

◇◆丶佛笑我妖孽 提交于 2019-12-25 02:39:04
问题 so I have the following test Go code which is designed to read from a binary file through stdin, and send the data read to a channel, (where it would then be processed further). In the version I've given here, it only reads the first two values from stdin, although that's fine as far as showing the problem is concerned. package main import ( "fmt" "io" "os" ) func input(dc chan []byte) { data := make([]byte, 2) var err error var n int for err != io.EOF { n, err = os.Stdin.Read(data) if n > 0